Published
Edited
Sep 30, 2019
5 forks
Insert cell
Insert cell
Insert cell
Insert cell
(param1, param2) => {
//code here
return 'something'
}
Insert cell
Insert cell
param => {
//code here
return 'something'
}
Insert cell
Insert cell
() => {
//code here
return 'something'
}
Insert cell
Insert cell
() => 'something'
Insert cell
Insert cell
Insert cell
fortune = (type='random') => {
var fortunes = ['you will be happy', 'you will be sad', 'you will eat pineapple']
if(type==='happy')
return `Your ${type} fortune: ${fortunes[0]}`
else if(type==='sad')
return `Your ${type} fortune: ${fortunes[1]}`
else
return `Your ${type} fortune: ${fortunes[Math.floor(Math.random() * 3)]}`
}
Insert cell
fortune()
Insert cell
Insert cell
mysteryFunction = ({bob=5, joe=10, mary=30}={}) => {
//some long and complicated code nobody can read
return bob*joe*mary
}
Insert cell
mysteryFunction()
Insert cell
Insert cell
sum = (...thingsToSum) => thingsToSum.reduce((sum,val) => sum+val)
Insert cell
sum(1,2,3,4)
Insert cell
Insert cell
Insert cell
ex1 =
{
var joe = function() {
return function(bob=3,joe=9,sam) {
if(bob&&joe&&sam)
{
return function(joey) {
return `${joey} is a pie, la la la`
}
}
else if (bob<joe)
{
return function(joeDimagio) {
return `'My name is ${joeDimagio}, and a hopeful nation turns its eyes to meeee'`
}
}
else
return `cool ${sam}`
}
}
class Doggo {
constructor(a,b,c) {
this.a=a;
this.b=b;
this.c=c;
}
randfunc() {
return joe;
}
randfuncII(sammy) {
const {a,b,...c} = sammy
function bob(a,b,{goo=5, gooo=13, ga=514, ...gaa}={}){
if(Object.keys(gaa).length>1)
return 153
else
return a+b+goo+gooo+ga
}(a,b,c)
return 'im a baby'
}
}
return Doggo
}
Insert cell
{
var ex = new ex1(1,2,3)
if(ex.randfuncII({})==='im a baby')
return "Your function will be tested here"
try {
expect(ex.a).to.equal(1)
expect(ex.b).to.equal(2)
expect(ex.c).to.equal(3)
expect(ex.randfunc()()(1,1,1)('bob')).to.equal(`bob is a pie, la la la`)
expect(ex.randfunc()()()('bob')).to.equal(`'My name is bob, and a hopeful nation turns its eyes to meeee'`)
expect(ex.randfunc()()(0,0,'Sammy')).to.equal(`cool Sammy`)
expect(ex.randfuncII({a:1, b:2, goo: 3, gooo: 10, ga:4, gaa:5})).to.equal(25)
expect(ex.randfuncII({a:1, b:5, goo: 'whaaaah', gooo: 'buuuurp', ga: 'ga', gaa: 'gaaaaa', gaaa: 'other baby noise'})).to.equal(153)
expect(ex.randfuncII()).to.equal(1+2+5+13+514)
return success()
}
catch(err) {
return failure()
}
}
Insert cell
import { expect, success, failure } from '@mmakutonin/chai-unit-testing-in-observable-notebook'
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