File tree Expand file tree Collapse file tree
Sprint-1/stretch/aoc-2018-day1 Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11const fs = require ( "fs" ) ;
2+ const path = require ( "path" ) ;
23
3- // read the file
4- let frequencies = fs . readFileSync ( "input.txt" , "utf-8" ) ;
4+ function solution ( ) {
5+ // set the file path
6+ const filePath = path . join ( __dirname , "input.txt" ) ;
57
6- // split the numbers by next line and covert them into Number
7- frequencies = frequencies . split ( "\n" ) . map ( ( num ) => Number ( num ) ) ;
8+ // read the file
9+ let frequencies = fs . readFileSync ( filePath , "utf-8" ) ;
810
9- // reduce to get the total = 529
10- console . log ( frequencies . reduce ( ( acc , num ) => acc + num , 0 ) ) ;
11+ // split the numbers by next line and covert them into Number
12+ frequencies = frequencies . split ( "\n" ) . map ( ( num ) => Number ( num ) ) ;
13+
14+ // reduce to get the total = 529
15+ const total = frequencies . reduce ( ( acc , num ) => acc + num , 0 ) ;
16+
17+ return total ;
18+ }
19+
20+ console . log ( solution ( ) ) ;
21+
22+ module . exports = solution ;
You can’t perform that action at this time.
0 commit comments