Published
Edited
Dec 7, 2021
Insert cell
Insert cell
Insert cell
Insert cell
totals = {
let totals =[]
for (var i = 0; i < h.length; i++) {
totals = totals.concat(h.map(x => Math.abs(x - i)).reduce((a,c) => a + c))
}
return totals
}
Insert cell
Insert cell
min = Math.min(...totals)
Insert cell
triangles = {
let totals =[]
for (var i = 0; i < h.length; i++) {
totals = totals.concat(h.map(x => triangular(Math.abs(x - i))).reduce((a,c) => a + c))
}
return totals
}
Insert cell
Insert cell
Insert cell
triangles.map((x,i) => { return {x: x, i: i}})
Insert cell
Math.min(...triangles)
Insert cell
Insert cell
function triangular(value) {
var abs = Math.abs(value);
return ((abs / 2) * (abs + 1)) * (abs / value) || 0;
};
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