Published
Edited
Dec 1, 2021
Insert cell
Insert cell
Insert cell
parse = ( list ) => list.split('\n').map( n => parseInt( n ) )
Insert cell
increases = ( list ) => {
let count = 0;
for ( let i = 1; i < list.length; i++ ) {
if ( list[i] > list[i-1] ) count++;
}
return count;
}
Insert cell
increases( parse( testInput ) )
Insert cell
Insert cell
Insert cell
increases( parse( input ) )
Insert cell
chunkByWindows = (list) => list.reduce( ( acc, n, idx, arr ) => {
if ( idx > arr.length - 3 ) return acc;
return [ ...acc, n + arr[idx + 1] + arr[idx + 2] ];
}, [])

Insert cell
chunkByWindows( parse( testInput ) )
Insert cell
increases( chunkByWindows( parse( testInput ) ) )
Insert cell
Insert cell
increases( chunkByWindows( parse( input ) ) )
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