Published
Edited
Oct 30, 2019
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
{
return array.element18
}
Insert cell
{
return array.size
}
Insert cell
{
return array.added5
}
Insert cell
{
return array.withoutLastElement
}
Insert cell
{
var arr = [1,2,3,4,5,6]
return arr.addArray
}
Insert cell
Insert cell
{
return 1=>0
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
bob = (a,b,c,d) => {
if(a<b || c>d) {
return (a,b,c,d) => a+b+c+(d||1)
} else if (b<1 && c>0)
return (a,r,t,s) => a-t+(s*t)-r*r
else if (b==a && c==d && a==c)
return (a) => a*2
else
return a+b+c+d;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
{
let resultArray = []
for( let i = 0; i< array.length; i++) {
if( array[i] < 30 ) resultArray.push(array[i])
}
return resultArray
}
Insert cell
Insert cell
lessThanThirty = x => x < 30
Insert cell
Insert cell
array.filter( lessThanThirty )
Insert cell
Insert cell
Insert cell
digitToLetters = x => (""+x).split("").map( d => ["a","b","c","d",'e','f','g','h','i','j'][d-1] ).join("")
Insert cell
array.map(digitToLetters)
Insert cell
Insert cell
Insert cell
Insert cell
reducer = (agg, curVal ) => agg + curVal
Insert cell
initialValue = 5
Insert cell
Insert cell
array.reduce(reducer, initialValue)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
arrowfy = function bob(a,n,s,w,e,r){
if(a==w*e)
return function awe(x,y){return x*y}
else if (a==r)
return function arrr(){return "Pirate"}
else if (e*r==e+e+w+e+e)
return function siren(emt){return "hi, my name is " + emt + " and I'm an EMT. What seems to be the problem today?"}
else if (n+s==a+s)
return 65
else
return function oops() {return null}
}
Insert cell
Insert cell
{
expect(arrowfy(5,0,0,1,5,1)(4,5)).to.equal(20)
expect(arrowfy(0,1,4,-15,5,1)("bob")).to.equal("hi, my name is bob and I'm an EMT. What seems to be the problem today?")
expect(arrowfy(1,1,4,-15,5,1)()).to.equal("Pirate")
expect(arrowfy(1,2,3,4,5)()).to.equal(null)
expect(arrowfy(4,4,5,1,1)).to.equal(65)
return success()
}
Insert cell
Insert cell
findDog = (arr) => arr //edit here to make the method
Insert cell
{
var cat = {secretSpecies: "catty"};
var imACatToo = {secretSpecies: "dog"}
var bob = {name: "bob"}
expect(findDog(["dog","doggo","cat","adsfnwaa adskndogsdsfnq", "mouse", "god","d og"])).to.equal(["cat","mouse", "god", "d og"])
expect(findDog(["dog"])).to.equal([])
expect(findDog([cat,imACatToo,bob,62, .01, "cat", null])).to.equal([cat,bob,62, .01, "cat", null])
return success()
}
Insert cell
Insert cell
catArr = (arr) => arr
Insert cell
{
var cat = {secretSpecies: "catty"};
var imACatToo = {secretSpecies: "dog"}
var bob = {name: "bob"}
expect(catArr(["dog","doggo","cat","adsfnwaa adskndogsdsfnq", "mouse", "god","d og"])).to.equal(["cat","cat","cat","cat","mouse", "god", "d og"])
expect(catArr(["dog"])).to.equal(["cat"])
expect(catArr([cat,imACatToo,bob,62, .01, "cat", null])).to.equal([cat,"cat",bob,62, .01, "cat", null])
return success()
}
Insert cell
Insert cell
numOfDogs = (arr) => 0
Insert cell
{
var cat = {secretSpecies: "catty"};
var imACatToo = {secretSpecies: "dog"}
var bob = {name: "bob"}
expect(numOfDogs(["dog","doggo","cat","adsfnwaa adskndogsdsfnq", "mouse", "god","d og"])).to.equal(3)
expect(numOfDogs(["dog"])).to.equal(1)
expect(numOfDogs([cat,imACatToo,bob,62, .01, "cat", null])).to.equal(1)
expect(numOfDogs([])).to.equal(0)
expect(numOfDogs(["cat"])).to.equal(0)
return success()
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more