1
1
mirror of https://github.com/theoludwig/programming-challenges.git synced 2024-12-08 00:45:29 +01:00
programming-challenges/challenges/pairwise/solutions/javascript-pairwise/solution.js
2020-07-08 19:56:30 +02:00

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