Public
Edited
Dec 9, 2022
Insert cell
Insert cell
Insert cell
Insert cell
perElfStrs = input.split("\n\n")
Insert cell
perElfNums = perElfStrs.map((perElfStr) =>
perElfStr.split("\n").map((numStr) => Number(numStr))
)
Insert cell
perElfSums = perElfNums.map((listOfNums) =>
listOfNums.reduce((acc, num) => acc + num)
)
Insert cell
answer = Math.max(...perElfSums)
Insert cell
Insert cell
sortedElfSums = perElfSums.sort((a, b) => b - a)
Insert cell
top3 = sortedElfSums.slice(0, 3)
Insert cell
answer2 = top3.reduce((acc, num) => acc + num)
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