Published
Edited
Dec 7, 2021
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// takes list of depth scans
// returns the number of increased depth scans
scanner = (
(list, current, previous) => list.map( // current and previous are simply local vars
(depth) => {
previous = current;
current = depth;
return current > previous;
}
)
.filter(k => k) //only pick increased depth scans
.length // finally, return the number of increased depth scans
)
Insert cell
**${AOC.timer(scanner, input, 1000)}**
Insert cell
Insert cell
slider = list => list.map((k, i, a) => k + a[i-1] + a[i-2])
Insert cell
scanner(input.map((k, i, a) => k + a[i+1] + a[i+2]))
Insert cell
threes = slider(input)
Insert cell
**${AOC.timer(scanner, threes, 1000)}**
Insert cell
Insert cell
Insert cell
testThrees = slider(testlist)
Insert cell
scanner(testThrees) === 5
Insert cell
Insert cell
Insert cell
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