From 0a755fe32432badfeb8114f2f4fc0458dfa7613f Mon Sep 17 00:00:00 2001 From: Aelita4 Date: Thu, 1 Dec 2022 11:37:59 +0100 Subject: [PATCH] 01_2 --- day01/index.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/day01/index.js b/day01/index.js index 363f433..10e62e8 100644 --- a/day01/index.js +++ b/day01/index.js @@ -19,10 +19,15 @@ input.split("\r\n").forEach(line => { } }); -let maxCalories = 0; +let maxCalories = [0, 0, 0]; elves.forEach(elf => { - if(elf > maxCalories) maxCalories = elf; + if(elf > maxCalories[0]) { + maxCalories[2] = maxCalories[1]; + maxCalories[1] = maxCalories[0]; + maxCalories[0] = elf; + } }); -console.log(maxCalories); \ No newline at end of file +console.log(`Elf with most calories: ${maxCalories[0]}`); +console.log(`Top 3 elves calories: ${maxCalories.reduce((e, acc) => acc += e)}`); \ No newline at end of file