-
Notifications
You must be signed in to change notification settings - Fork 0
/
01.js
37 lines (32 loc) · 781 Bytes
/
01.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const fs = require("fs");
const readline = require("readline");
let input = [];
async function processLineByLine() {
const fileStream = fs.createReadStream("input_for_1_2.txt");
const rl = readline.createInterface({
input: fileStream,
crlfDelay: Infinity,
});
let sum = 0;
rl.on("line", (word) => {
let first;
let last;
for (let x = 0; x < word.length; x++) {
if (Number.isInteger(Number.parseInt(word[x]))) {
first = word[x];
break;
}
}
for (let x = word.length; x >= 0; x--) {
if (Number.isInteger(Number.parseInt(word[x]))) {
last = word[x];
break;
}
}
sum += parseInt("" + first + last);
});
rl.on("close", () => {
console.log(sum);
});
}
processLineByLine();