Answers for "generate combinations of values from multiple array javascript"

0

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;
}
Posted by: Guest on March-28-2021
-1

get combinations of two js

var array1=["A","B","C"];

var array2=["1","2","3","4"];

console.log(array1.flatMap(d => array2.map(v => d + v)))
Posted by: Guest on October-13-2020

Code answers related to "generate combinations of values from multiple array javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language