I have two arrays lets say
var termRateOptionsArr = [{
"term": 48,
"rate": 2.99,
"residualPercent": 0
}, {
"term": 60,
"rate": 1.99,
"residualPercent": 0
}, {
"term": 72,
"rate": 0.99,
"residualPercent": 0
}];
var cashDownOptionsArr = [{
"cashdown": "2000"
}, {
"cashdown": "4000"
}, {
"cashdown": "6000"
}];
I want to combine these two arrays into a matrix combination using the following code:
var cartesian = function() {
var combos = _.reduce(arguments, function(a, b) {
return _.flatten(_.map(a, function(x) {
return _.map(b, function(y) {
return x.concat([y]);
});
}), true);
}, [ [] ]);
return _.flatten(_.map(combos, function(item) {
return _.extend(item[0], item[1]);
}));
};
console.table( cartesian(termRateOptionsArr,cashDownOptionsArr));
I having issues combining I am getting only the last item array value instead of each item in the array. I think it has to do with some closure issue but not sure... Any help is appreciated..