Public
Edited
Apr 12, 2023
1 fork
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
{
const array = [];
for (let i = 0; i < 10; i++) {
array.push(i);
}
return array;
}
Insert cell
d3.range(10)
Insert cell
Insert cell
{
const array = [5, 3, 1, 0, null, 3];
const newArray = [];
for (let i = 0; i < array.length; i++) {
if (array[i] !== null) {
newArray.push(array[i]);
}
}
return newArray;
}
Insert cell
[5, 3, 1, 0, null, 3].filter((n) => n !== null)
Insert cell
Insert cell
{
const array = [];

for (let i = 0; i < 10; i++) {
array.push(i);
}

const newArray = [];

for (let i = 0; i < array.length; i++) {
newArray.push(array[i] * 3);
}

return newArray;
}
Insert cell
d3.range(10).map((n) => n * 3)
Insert cell
Insert cell
{
const array = [];

for (let i = 0; i < 10; i++) {
array.push([]);
for (let j = 0; j < 10; j++) {
array[i].push(j);
}
}

return array;
}
Insert cell
d3.range(10).map((n) => d3.range(10))
Insert cell
Insert cell
[2, 5, 8, 12].reduce((acc, val) => acc * val, 1)
Insert cell
Insert cell
[2, 5, 8, 12].reduce((acc, val) => acc + val, 0)
Insert cell
Insert cell
[
{ order: "carnivora", animal: "cat" },
{ order: "carnivora", species: "dog" },
{ order: "carnivora", species: "ferret" },
{ order: "passeriformes", species: "canary" },
{ order: "columbiformes", species: "pigeon" },
{ order: "artiodactyl", species: "pig" },
{ order: "artiodactyl", species: "sheep" }
].reduce((acc, animal) => {
//check if the accumulator already has a key for the animal's order
if (acc[animal.order]) {
//if so, add the animal
acc[animal.order].push(animal);
} else {
//otherwise, make a new key and add the current animal to it in an array
acc[animal.order] = [animal];
}
return acc;
}, {}) //the {} means we are starting with an empty object
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