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

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