Array: [['a'.'b'], ['n'.'m'], ['0'.'1'[] = [] = ["an0"."an1"."am0"."am1"."bn0"."bn1"."bm0"."bm1"]
Copy the code
binary
an0 => 0 - 0 - 0;
an1 => 0 - 0 - 1;
am0 => 0 - 1 - 0;
am1 => 0 - 1 - 1;
bn0 => 1 - 0 - 0;
bn1 => 1 - 0 - 1;
bm0 => 1 - 1 - 0;
bm1 => 1 - 1 - 1;
Copy the code
let clapArr = [['a'.'b'], ['n'.'m'], ['0'.'1']], newArray = [], newClapArr = [];
// 8 = Math.pow(clapArr[0].length,clapArr.length)
for (let i = 0; i < 8; i++) {
let newStr = i.toString(2).length < 2 ?
'00' + i.toString(2) :
i.toString(2).length < 3 ?
'0' + i.toString(2) :
i.toString(2);
newArray.push(newStr);
}
console.log(newArray);/ / [' 000 ', '001', '010', '011', '100', '101', '110', '111');
for (let i = 0; i < newArray.length; i++) {
let str = ' ';
newArray[i].split(' ').forEach((key, ind) = > {
clapArr.forEach((item, index) = > {
index == ind ? str += item[key] : null;
});
});
newClapArr.push(str);
}
console.log(newClapArr);//['an0', 'an1', 'am0', 'am1', 'bn0', 'bn1', 'bm0', 'bm1']
Copy the code