mirror of
https://github.com/theoludwig/programming-challenges.git
synced 2025-05-18 12:02:53 +02:00
✨ Add "pairwise" challenge
This commit is contained in:
@ -0,0 +1,4 @@
|
||||
# javascript-pairwise - pairwise
|
||||
|
||||
Programming language : JavaScript
|
||||
Created by [@Divlo](https://github.com/Divlo) at 8 July 2020.
|
@ -0,0 +1,15 @@
|
||||
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
|
Reference in New Issue
Block a user