[Solved] How to generate the combinations of the following in js


okay so after spending sometime i figured it out

options = ['color', 'size'];
optionsValues= [['Red','Blue'], ['L', 'XS']];

function combination() {
    var r = [], arg = arguments[0], max = arg.length-1;
    function helper(arr, i) {
        for (var j=0, l=arg[i].length; j<l; j++) {
            var a = arr.slice(0); // clone arr
            var obj = {};
            obj[options[i]] = arg[i][j];
            a.push(obj); 
            if (i==max){
                str="";
                for(var c = a.length - 1 ; c >= 0; c--){
                  if(c == 0){
                    str += a[c][options[c]];
                  }else{
                    str += a[c][options[c]] + ',';
                  }
                }
                r[str] = a;
            }
            else
                helper(a, i+1);
        }
    }
    helper([], 0);
    return r;
}

console.log(combination(optionsValues));

solved How to generate the combinations of the following in js