![]() |
[Hackerrank] Solution of Divisible Sum Pairs in JavaScript |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function divisibleSumPairs(n, k, ar) { | |
let result = 0; | |
for(let i = 0; i < n - 1; i++) { | |
result += ar.slice(i + 1, n).filter((item, index) => { | |
if ((item + ar[i]) % k === 0) { | |
return item; | |
} | |
}).length; | |
} | |
return result; | |
} |