mirror of
https://github.com/jcreek/advent-of-code.git
synced 2026-07-13 11:13:47 +00:00
Import AdventOfCode2018 JavaScript solutions
git-subtree-dir: AdventOfCode JS/2018 git-subtree-mainline:b44957b275git-subtree-split:5e9be1b66b
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
// AdventOfCode2018-01
|
||||
var fs = require('fs');
|
||||
var frequency = 0;
|
||||
|
||||
var textFile = fs.readFileSync('./input.txt').toString();
|
||||
var textArray = textFile.split(/\r?\n/);
|
||||
|
||||
textArray.forEach(line => {
|
||||
if (line.substr(0,1) == '+') {
|
||||
frequency += parseInt(line.substr(1));
|
||||
}
|
||||
else {
|
||||
frequency -= parseInt(line.substr(1));
|
||||
}
|
||||
});
|
||||
|
||||
console.log('The resulting frequency is ' + frequency);
|
||||
Reference in New Issue
Block a user