R.map(Number),// note: turns empty lines into 0; no problem since does not affect sum per Elf
R.groupWith(R.identity),// group by falsy borders: the 0s
R.map(R.sum),// sum per Elf
)(list)
// just pick Elf with maximum calories: 4th Elf in this case
part1Answer=R.pipe(
caloriesPerElf,
R.apply(Math.max)
)
(part1ExampleText)
totalCaloriesTop3=(list)=>R.pipe(
caloriesPerElf,// get list of total calories per Elf
R.sort(descending),// sort descending
R.slice(0,3),// grab top three
R.sum,// and sum
)(list)
descending=(a,b)=>b-a
totalCaloriesTop3(part1ExampleText)
totalCaloriesTop3(input)
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.