This commit is contained in:
Aelita4 2022-12-01 11:37:59 +01:00
parent 731cd6422f
commit 0a755fe324
Signed by: Aelita4
GPG Key ID: C217320B9C5FD53B
1 changed files with 8 additions and 3 deletions

View File

@ -19,10 +19,15 @@ input.split("\r\n").forEach(line => {
} }
}); });
let maxCalories = 0; let maxCalories = [0, 0, 0];
elves.forEach(elf => { 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); console.log(`Elf with most calories: ${maxCalories[0]}`);
console.log(`Top 3 elves calories: ${maxCalories.reduce((e, acc) => acc += e)}`);