Published
Edited
Sep 27, 2019
6 forks
Insert cell
Insert cell
Insert cell
function bob( joe ) {
return joe + ' is a ' + joe
}
Insert cell
function joe ( potter ) {
return potter.indexOf('\'Arry of Hogwarts')
}
Insert cell
function resurrected ( days ) {
if(days>=3)
return true
else
return false
}
Insert cell
function jimbo() {
return {
bob: 'bob',
jim: 'jimbo',
yo: function() {
return 'yo'
}
}
}
Insert cell
Insert cell
Insert cell
function sum(a, b) {
return a+b
}
Insert cell
function mult(a, b) {
return a*b
}
Insert cell
function execFunction (func, a, b) {
return func(a,b)
}
Insert cell
execFunction(mult, 5, 2)
Insert cell
function retFunction(func1, func2, selector) {
if(selector)
return func1
else
return func2
}
Insert cell
retFunction(sum,mult,true)(5,10)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function getDog(animal) {
if(animal.species==='dog')
return true
return false
}
Insert cell
function getCat(animal) {
if(animal.species==='cat' || animal.species==='kitty')
return true
return false
}
Insert cell
Insert cell
animalArray.filter(getDog)
Insert cell
animalArray.filter(getCat)
Insert cell
Insert cell
Insert cell
function countCats( currentCount, animal) {
if(animal.species==='cat'||animal.species==='kitty')
return currentCount + 1
return currentCount
}
Insert cell
animalArray.reduce(countCats, 0)
Insert cell
Insert cell
Insert cell
Insert cell
function getAnimalName(animal) {
return animal.name
}
Insert cell
animalArray.map(getAnimalName)
Insert cell
Insert cell
Insert cell
kittyArray = ['bob', 'sammy', 'hello', 'sammy', 'just a kitty', 'super kitty', 'mr. butters']
Insert cell
Insert cell
function toName( inputArray ) {
//Code Here
}
Insert cell
{
if(toName([])===undefined)
return "Your function will be unit tested here"
try
{
var arry = ['bob', 'sammy', 'hello', 'sammy', 'just a kitty', 'super kitty', 'mr. butters']
expect(toName(arry)).to.equal('bob, sammy, hello, sammy, just a kitty, super kitty, mr. butters')
expect(toName(arry.slice(0,3))).to.equal('bob, sammy, hello')
expect(toName(arry.slice(6))).to.equal('mr. butters')
return success()
}
catch(err)
{
return failure()
}
}
Insert cell
Insert cell
function toObject( inputArray ) {
//Code Here
}
Insert cell
{
if(toObject([])===undefined)
return "Your function will be unit tested here"
try
{
var arry = ['bob', 'sammy', 'hello', 'sammy', 'just a kitty', 'super kitty', 'mr. butters']
expect(toObject(arry)).to.deep.equal([{name: 'bob', species:'cat'},
{name: 'sammy', species:'cat'},
{name: 'hello', species:'cat'},
{name: 'sammy', species:'cat'},
{name: 'just a kitty', species:'cat'},
{name: 'super kitty', species:'cat'},
{name: 'mr. butters', species:'cat'}])
expect(toObject(arry.slice(4))).to.deep.equal([{name: 'just a kitty', species:'cat'},
{name: 'super kitty', species:'cat'},
{name: 'mr. butters', species:'cat'}])
expect(toObject(arry.slice(4,5))).to.deep.equal([{name: 'just a kitty', species:'cat'}])
return success()
}
catch(err)
{
return failure()
}
}
Insert cell
Insert cell
function toCart( foodArray ) {
//Code Here
}
Insert cell
{
if(toCart([])===undefined)
return "Your function will be unit tested here"
try
{
var arry = ['xyz (cat)', 'z (cat)', 'jimbo (dog)', 'arrrrr (pirate)', 'steak pate (cat)']
expect(toCart(arry)).to.deep.equal(['xyz (cat)', 'z (cat)', 'steak pate (cat)'])
expect(toCart(arry.slice(0,3))).to.deep.equal(['xyz (cat)', 'z (cat)'])
expect(toCart(arry.slice(4))).to.deep.equal(['steak pate (cat)'])
return success()
}
catch(err)
{
return failure()
}
}
Insert cell
Insert cell
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