Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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);
});
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #pairing #array #javascript #array
ADD COMMENT
Topic
Name
1+5 =