mirror of
https://github.com/theoludwig/programming-challenges.git
synced 2024-12-08 00:45:29 +01:00
16 lines
422 B
JavaScript
16 lines
422 B
JavaScript
function solution (arr, arg) {
|
|
return arr.reduce((accumulator, currentNumber, indexReduce, array) => {
|
|
for (let index = indexReduce + 1; index < array.length; index++) {
|
|
if (array[index] + array[indexReduce] === arg) {
|
|
accumulator += indexReduce + index
|
|
array[indexReduce] = NaN
|
|
array[index] = NaN
|
|
break
|
|
}
|
|
}
|
|
return accumulator
|
|
}, 0)
|
|
}
|
|
|
|
module.exports = solution
|