Answers for "every possible pairing in an array javascript in new array"

0

every possible pairing in an array javascript in new array

function pairs(arr) {
    var res = [],
        l = arr.length;
    for(var i=0; i<l; ++i)
        for(var j=i+1; j<l; ++j)
            res.push([arr[i], arr[j]]);
    return res;
}
pairs([1, 2, 3]).forEach(function(pair){
    console.log(pair);
});
Posted by: Guest on October-15-2020

Code answers related to "every possible pairing in an array javascript in new array"

Code answers related to "Javascript"

Browse Popular Code Answers by Language