const fs = require('fs'); const input = fs.readFileSync('./day-1/input.txt').toString(); const TOP_AMOUNT = 3; const lines = input.split('\n'); const result = lines.reduce((acc, line) => { if (line === '') { acc.sums.push(acc.current); acc.current = 0; } else acc.current += parseInt(line); return acc; }, { current: 0, sums: [] }); const topSums = result.sums.sort((a, b) => b - a).slice(0, TOP_AMOUNT); const totalTopSum = topSums.reduce((acc, value) => acc + value, 0); console.log(totalTopSum);