Published
Edited
May 26, 2022
Importers
3 stars
Insert cell
Insert cell
chunk([1, 2, 3, 4, 5, 6, 7, 8], 5)
Insert cell
chunk = (array, size) => {
return array.reduce((arr, item, idx) => {
return idx % size === 0
? [...arr, [item]]
: [...arr.slice(0, -1), [...arr.slice(-1)[0], item]];
}, []);
}
Insert cell
groupBy([1.2, 1.3, 1.5, 1.6, 1.9, 2], (v) => Math.round(v))
Insert cell
function groupBy(array, fn) {
return array.reduce(
(r, v, i, a, k = fn(v)) => ((r[k] || (r[k] = [])).push(v), r),
{}
);
}
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