From 14cf5c547909fb4e60fe75cfa73d56013b3aa590 Mon Sep 17 00:00:00 2001 From: vicentpc95 Date: Sat, 9 Dec 2023 13:08:54 +0100 Subject: [PATCH] dia1 reimplementado --- javascript/day1/day1.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/javascript/day1/day1.js b/javascript/day1/day1.js index b989cc3..19057b5 100644 --- a/javascript/day1/day1.js +++ b/javascript/day1/day1.js @@ -14,14 +14,23 @@ data = data.replaceAll("nine", "n9e") let sumNum = 0 let lines = data.split("\n") + for (let line of lines){ + let lineStr = "" for (let char of line){ - isNum(char) + if(isNum(char)){ + lineStr += char + } } + let twoNum = lineStr[0] + lineStr[lineStr.length - 1] + twoNum = parseInt(twoNum) + sumNum += twoNum } +console.log(sumNum) + function isNum(testchar){ - if (testchar == "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"){ + if (testchar == "1" || testchar == "2" || testchar == "3" || testchar == "4" || testchar == "5" || testchar == "6" || testchar == "7" || testchar == "8" || testchar == "9"){ return testchar } } \ No newline at end of file