Public
Edited
Apr 22, 2023
Insert cell
Insert cell
Insert cell
Insert cell
myArray = [1,2,3,4,5,6,7,8,9,10]
Insert cell
Insert cell
/// Use map() to achieve the above result
myArray.map(d => d*10)
Insert cell
Insert cell
/// Use filter() to achieve the above result
myArray.filter(d => d<5)
Insert cell
Insert cell
Insert cell
// Import the `myDataset` cell from the previous notebook as the 'ages' cell of this notebook
import {myDataset} from "f7eab43ecb1c601d"
Insert cell
Insert cell
myDataset
Insert cell
Insert cell
// You can use Inputs.table()
Inputs.table(myDataset, {width: 600})
Insert cell
Insert cell
// Map() can do the trick
myDataset.map(d => d.name)
Insert cell
Insert cell
// Filter() would be useful here
myDataset.filter(d => d.name=== 'Gandalf')
Insert cell
// What would happen if you were to use `map()` instead of `filter()`? Try and find out.
myDataset.map(d => d.name=== 'Gandalf')

//with map() instead of filter(), an array is returned containing "true" for each element in myDataset that has a 'name' property matching 'Gandalf' and 'false' for all other elements
Insert cell
Insert cell
// Filter() could help here
myDataset.filter(d => d.age>20_000)
Insert cell
Insert cell
myDataset.filter(d => d.age< 1000)
Insert cell
Insert cell
Insert cell
import {imageToDo} from "@clokman/student-blocks"
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