diff options
Diffstat (limited to 'day-1/index.js')
-rw-r--r-- | day-1/index.js | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/day-1/index.js b/day-1/index.js new file mode 100644 index 0000000..512deea --- /dev/null +++ b/day-1/index.js @@ -0,0 +1,15 @@ +const fs = require('fs'); +const input = fs.readFileSync('./day-1/input.txt').toString(); + +const lines = input.split('\n'); +const result = lines.reduce((acc, line) => { + if (line === '') { + if (acc.current > acc.greatest) acc.greatest = acc.current; + acc.current = 0; + } else acc.current += parseInt(line); + + return acc; +}, { current: 0, greatest: 0 }); + +console.log(result); + |