Published
Edited
Jan 21, 2021
Importers
Insert cell
Insert cell
Insert cell
min = Math.min
Insert cell
max = Math.max
Insert cell
// test for long lists
max(...Array(25600).fill(0), 1) === 1
Insert cell
sum = xs => xs.reduce((acc, x) => acc + x, 0)
Insert cell
sum([1, 2, 3]) === 6
Insert cell
clamp = (value, low, high) => Math.min(high, Math.max(low, value))
Insert cell
map = (value, start0, end0, start1, end1, clampResult) => {
let result = (value - start0) * (end1 - start1) / (end0-start0) + end1;
return clampResult ? clamp(result) : result
}
Insert cell
Insert cell
random = {
return function r(n) {
return Array.isArray(n)
? n[Math.floor(r(n.length))]
: n === undefined
? Math.random()
: n * Math.random();
};
}
Insert cell
random(['a', 'b', 'c'])
Insert cell
random()
Insert cell
random(10)
Insert cell
random(10, 20)
Insert cell
md`## range`
Insert cell
function* range(a, b) {
if (b === undefined) [a, b] = [0, a];
for (let i = Math.floor(a); i < b; i++) {
yield i;
}
}
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more