3b complete
This commit is contained in:
parent
047ecbd685
commit
3acbec3d91
2 changed files with 37 additions and 8 deletions
17
3/index3a.js
Normal file
17
3/index3a.js
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
const fs = require("fs")
|
||||
const regEx = /mul\(\d+,\d+\)/g
|
||||
let total = 0
|
||||
const input = fs.readFileSync("input.txt","utf-8")
|
||||
const result = input.match(regEx)
|
||||
// console.log("hello world")
|
||||
console.log(result)
|
||||
result.forEach((mulString)=>{
|
||||
const numRegex= /\d+/g
|
||||
const numbers = mulString.match(numRegex)
|
||||
console.log(...numbers)
|
||||
const aVal =parseInt(numbers[0])
|
||||
const bVal=parseInt(numbers[1])
|
||||
total += aVal*bVal
|
||||
})
|
||||
|
||||
console.log("total: ",total)
|
||||
Loading…
Add table
Add a link
Reference in a new issue