initial upload
This commit is contained in:
35
2024/07/index.js
Normal file
35
2024/07/index.js
Normal file
@ -0,0 +1,35 @@
|
||||
import fs from 'node:fs'
|
||||
function add(a, b) {
|
||||
return a + b
|
||||
}
|
||||
function mul(numbers) {
|
||||
const res = numbers.reduce((acc, next) => { console.log(acc, next); return acc * next }, 0)
|
||||
//console.log(res)
|
||||
return 0
|
||||
}
|
||||
|
||||
function testMathOperations(product, numbers) {
|
||||
let result = 0
|
||||
const operations = numbers.length - 1
|
||||
|
||||
|
||||
//let res = mul(numbers)
|
||||
//let res = product == numbers.reduce((acc, next) => { acc * next }, 0) ? result : 0
|
||||
|
||||
if (product === result) return product
|
||||
return 0
|
||||
}
|
||||
|
||||
fs.readFile('example.txt', ({ encoding: 'utf-8' }), (err, data) => {
|
||||
const regex = /^(\d+): ([0-9 ]+)/g
|
||||
let result = 0
|
||||
for (let line of data.split('\n')) {
|
||||
const test = line.matchAll(regex).next().value
|
||||
const product = test[1]
|
||||
const numbers = test[2].split(' ')
|
||||
result += testMathOperations(product, numbers)
|
||||
console.log(product, numbers, result)
|
||||
//console.log(`something should happen to ${numbers} for becoming ${result}`)
|
||||
}
|
||||
console.log(result)
|
||||
})
|
Reference in New Issue
Block a user