From 2d980c77177c00ccd0cbc0e3a8a5454490d38fa3 Mon Sep 17 00:00:00 2001 From: Baipyrus Date: Sat, 9 Dec 2023 22:42:38 +0100 Subject: [PATCH] mutable instead of array of size 1 --- Day9/Part1.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Day9/Part1.js b/Day9/Part1.js index 6782614..d6d403e 100644 --- a/Day9/Part1.js +++ b/Day9/Part1.js @@ -20,13 +20,13 @@ const predictions = histories.map((e) => { }, []); } const last = sequences.pop(); - const extrapolated = [[...last, last[0]]]; + let extrapolated = [...last, last[0]]; for (const s of sequences.reverse()) { const current = s.pop(); - const last = extrapolated.pop().pop(); - extrapolated.push([...s, current + last]); + const last = extrapolated.pop(); + extrapolated = [...s, current + last]; } - return extrapolated.pop().pop(); + return extrapolated.pop(); }); const sum = predictions.reduce((a, i) => a + i); console.log(sum);