Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

generate combinations of values from multiple array javascript

function cartesian(...args) {
    var r = [], max = args.length-1;
    function helper(arr, i) {
        for (var j=0, l=args[i].length; j<l; j++) {
            var a = arr.slice(0); // clone arr
            a.push(args[i][j]);
            if (i==max)
                r.push(a);
            else
                helper(a, i+1);
        }
    }
    helper([], 0);
    return r;
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #generate #combinations #values #multiple #array #javascript
ADD COMMENT
Topic
Name
3+5 =