Public
Edited
Dec 2, 2021
Insert cell
Insert cell
Insert cell
/*
** Calculate the number of increases in an array of depth measurements.
*/
function calc_num_increases(depth_data) {
let num_increases = 0;
for (let index = 1; index < depth_data.length; ++index) {
if (parseFloat(depth_data[index]) > parseFloat(depth_data[index-1])) {
num_increases += 1;
}
}
return num_increases;
}
Insert cell
Insert cell
calc_num_increases(test_depth_data) // Should return 7
Insert cell
Insert cell
calc_num_increases(depth_data)
Insert cell
Insert cell
/*
** Calculate the sum of a three-measurement sliding window of depth data.
*/
function calc_sliding_sums(depth_data) {

let three_measure_sums = [];
for (let index = 0; index < depth_data.length-2; ++index) {
three_measure_sums.push(parseFloat(depth_data[index]) + parseFloat(depth_data[index+1]) + parseFloat(depth_data[index+2]))
}

return three_measure_sums
}
Insert cell
calc_num_increases(calc_sliding_sums(test_depth_data)) // Should return 5
Insert cell
calc_num_increases(calc_sliding_sums(depth_data))
Insert cell
Insert cell
Insert cell
test_depth_data = [199, 200, 208, 210, 200, 207, 240, 269, 260, 263]
Insert cell
Insert cell
parseFloat(depth_data[0])
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