javascript solutions and split the python to both parts

This commit is contained in:
rain
2023-12-05 18:43:04 -06:00
parent da4e57c63e
commit 2866561b22
4 changed files with 80 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
const path = require('path');
const fs = require('fs');
const input = fs
.readFileSync('../input.txt', 'utf8')
.toString()
.trim()
.split('\n');
function add(num, oldSum) {
return num + oldSum;
}
var sum = input.map(function(line) {
line = line.replace(/\D/g,'');
return parseInt(line[0]+line.slice(-1));
}).reduce(add,0);
console.log(sum);