Skip to content

Commit 8815813

Browse files
committed
updated solution.js
1 parent d6a4399 commit 8815813

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
const 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;

0 commit comments

Comments
 (0)