aoc/aoc_2023/day-01/main_1.js
Elizabeth (Lizzy) Hunt cdb12dbc28
Template (#1)
* tempalte foo

* buff aoc stuff
2023-12-01 15:49:11 -07:00

19 lines
414 B
JavaScript

const fs = require("node:fs");
const data = fs.readFileSync("input.txt", "utf8");
const res = data
.split("\n")
.filter((line) => line && line != "")
.map((line) => line.replaceAll(/[^0-9]*/g, ""))
.reduce((acc, line) => {
const nums = line.split("");
const first = parseInt(nums.at(0));
const last = parseInt(nums.at(-1));
return acc + (first * 10 + last);
}, 0);
console.log(res);