Public
Edited
Sep 6, 2024
Fork of Map vs For
1 fork
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
cube0 = (x) => Math.pow(x, 3)
Insert cell
cube1a = (x, id) => Math.pow(x, 3)
Insert cell
cube1b = (x, id) => Math.pow(x, 3) + 0 * id
Insert cell
cube2a = (x, id, A) => Math.pow(x, 3)
Insert cell
cube2b = (x, id, A) => Math.pow(x, 3) + 0 * id + A[id] * 0
Insert cell
// experiments are an array of objects with a name and a function to run.
experiments = [
{name: 'map cube', run: ()=>math.map(A, math.cube)},
{name: 'map cube callback', run: ()=>math.map(A, x => math.cube(x))},
{name: 'map a found signature', run: ()=>{
const fn = math.typed.find(math.cube, 'number')
return math.map(A, fn)
}},
{name: 'map a regular function', run:()=>math.map(A,cube0)},
{name: 'map a typed function', run:()=>math.map(A, math.cube)},
{name: 'map a regular function with 2 args', run:()=>math.map(A,cube1a)},
{name: 'map a typed function with 2 args', run:()=>math.map(A, math.cube)},
{name: 'map a regular function with 2 args using them', run:()=>math.map(A,cube1b)},
{name: 'map a typed function with 2 args using them', run:()=>math.map(A, math.typed({'number, any':cube1b}))},
{name: 'map a regular function with 3 args', run:()=>math.map(A,cube2a)},
{name: 'map a typed function with 3 args', run:()=>math.map(A, math.typed({'number, any, any':cube2a}))},
{name: 'map a regular function with 3 args using them', run:()=>math.map(A,cube2b)},
{name: 'map a typed function with 3 args using them', run:()=>math.map(A, math.typed({'number, any, any':cube2b}))},
]
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
math = import("https://cdn.jsdelivr.net/npm/mathjs@latest/+esm")
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