参考博客:https://blog.csdn.net/maxsky/article/details/80196323
function calcDescartes (array) {
if (array.length < 2) {
return array[0] || []
}
else {
return [].reduce.call(array, function (prev, cur) {
let res = []
prev.forEach(function (c) {
set.forEach(function (s) {
let t = [].concat(c)
t.push(s)
res.push(t)
})
})
return res
})
}
}
console.log(calcDescartes([[1, 2], ['a', 'b']]))
console.log(calcDescartes([[1, 2], ['a', 'b'], ['+', '-']]))