Published
Edited
Dec 8, 2021
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
slider = (data) => {
return data.filter((d,i) => {
let value = data[i] - data[i - 1]
return (value > 0)
})
}
Insert cell
slider(measurements)
Insert cell
Insert cell
sliding_totals = measurements.map((x, index) => {
return measurements[index] + measurements[index - 1] + measurements[index - 2]
})
Insert cell
slider(sliding_totals)
Insert cell
Insert cell
generic_slider = (data, n) => {
return data.filter((d, i, a) => {
// skip the indices before n because they're null AND
return i >= n && a
// grab the slice of a using the current index then subtract 1 from n
// and the index +1 to always give you n numbers
.slice(i-(n-1), i+1)
// add up the slice
.reduce((acc,d)=>acc+d) >
// see if its greater than the prior slice (not n-1)
a.slice(i-n, i).reduce((acc,d)=>acc+d)
})
}
Insert cell
generic_slider(measurements, 1)
Insert cell
generic_slider(measurements, 3)
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