Public
Edited
Dec 3, 2022
1 fork
1 star
Insert cell
Insert cell
Insert cell
maxCalories = {
let count = 0;
let max = 0;
for (const cal of input) {
if (cal.length === 0) {
max = Math.max(max, count);
count = 0;
} else {
count += +cal;
}
}
return max;
}
Insert cell
Insert cell
maxThreeCalories = {
let count = 0;
const counts = [];
for (const cal of input) {
if (cal.length === 0) {
counts.push(count);
count = 0;
} else {
count += +cal;
}
}
counts.sort((a, b) => b - a);
return counts[0] + counts[1] + counts[2];
}
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