function doCombination(arr) {
var count = arr.length - 1; //数组长度(从0开始)
var tmp = [];
var totalArr = [];// 总数组
return doCombinationCallback(arr, 0);//从第一个开始
//js 没有静态数据,为了避免和外部数据混淆,需要使用闭包的形式
function doCombinationCallback(arr, curr_index) {
for(val of arr[curr_index]) {
tmp[curr_index] = val;//以curr_index为索引,加入数组
//当前循环下标小于数组总长度,则需要继续调用方法
if(curr_index < count) {
doCombinationCallback(arr, curr_index + 1);//继续调用
}else{
totalArr.push(tmp);//(直接给push进去,push进去的不是值,而是值的地址)