Published
Edited
Apr 6, 2021
1 star
Insert cell
Insert cell
Insert cell
Insert cell
a = [1,2,3,4,5]
Insert cell
Insert cell
sqr = a => a * a
Insert cell
Insert cell
a.map(sqr)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
b = ({ a: 1, b: 2, c: 3 })
Insert cell
Insert cell
c = ({ a: 1, b: 4, c: 9 })
Insert cell
Insert cell
mapObj = fn => obj => {
let newObj = {}
for (let key in obj) {
newObj[key] = fn(obj[key])
}
return newObj
}
Insert cell
Insert cell
Insert cell
mapObj(sqr)(b)
Insert cell
Insert cell
Insert cell
mapObj1 = fn => obj => {
const kvPairs = Object.entries(obj)
const newKvPairs = kvPairs.map(([key, value]) => [key, fn(value)])
return Object.fromEntries(newKvPairs)
}
Insert cell
mapObj1(sqr)(b)
Insert cell
Insert cell
b
Insert cell
Object.entries(b)
Insert cell
Insert cell
Insert cell
d = [
["x", 1],
["y", 2],
["z", 3]
]
Insert cell
Insert cell
Object.fromEntries(d)
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