blob: 9e444baf342290bd1d9887dfae4b73e22197b453 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
import fs from "fs";
const input = fs.readFileSync("./input.txt").toString();
const result = input
.split("\n")
.slice(0, -1)
.map((line) => line.match(/\d/g))
.reduce((acc, value) => {
if (!value)
throw new Error(`The string must contain at least one digit ${value}`);
return acc + Number(value[0] + value[value.length - 1]);
}, 0);
console.log({ result });
|