-
Notifications
You must be signed in to change notification settings - Fork 0
/
day1.js
39 lines (34 loc) · 929 Bytes
/
day1.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
38
39
var lineReader = require('readline').createInterface({
input: require('fs').createReadStream('day1.input')
});
var elves = [];
var currentElf = 0;
var biggestElf = 0;
lineReader.on('line', function (line) {
// Each line in input.txt will be successively available here as `line`.
var line = line.trim();
console.log({line})
if(line){
var current = parseInt(line);
console.log({current})
console.log(typeof current)
currentElf += current;
console.log({currentElf})
console.log(typeof currentElf)
} else {
console.log("next elf!")
elves.push(currentElf);
biggestElf = ((currentElf > biggestElf) ? currentElf : biggestElf);
currentElf = 0;
}
});
lineReader.on('close', function() {
console.log({elves})
elves = elves.sort(function(a, b) {
return b - a;
});
var biggest = elves[0];
console.log({elves})
console.log({biggest})
console.log({biggestElf})
})