Public
Edited
Dec 1, 2022
Insert cell
Insert cell
Insert cell
parse = (input) => {
return input.split("\n\n").map((e) => e.split("\n").map((n) => parseInt(n)));
}
Insert cell
parse(testInput)
Insert cell
part1 = (input) => {
const elves = parse(input);
const calories = elves.map((e) => e.reduce((a, b) => a + b));
return Math.max.apply(null, calories);
}
Insert cell
part1(testInput)
Insert cell
Insert cell
part1(input)
Insert cell
part2 = (input) => {
const elves = parse(input);
const calories = elves.map((e) => e.reduce((a, b) => a + b));
const sorted = calories.sort((a, b) => b - a);
return sorted[0] + sorted[1] + sorted[2];
}
Insert cell
part2(testInput)
Insert cell
part2(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