Created
December 18, 2019 05:24
-
-
Save hddananjaya/c16f1e25f1a903ffc50c5365d29e9ab3 to your computer and use it in GitHub Desktop.
Return all combination pairs.
This file contains hidden or 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 getPairs(arr){ | |
var pairsList = []; | |
for (var i=0; i < arr.length - 1; i++){ | |
for (var j=i+1; j < arr.length; j++){ | |
pairsList.push([arr[i], arr[j]]); | |
} | |
} | |
return (pairsList); | |
} | |
var S = [1, 7, 2, 4]; | |
console.log(getPairs(S)); | |
// [[1, 7], [1, 2], [1, 4], [7, 2], [7, 4], [2, 4]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment