Skip to content

Latest commit

 

History

History
20 lines (16 loc) · 412 Bytes

多维数组合并.md

File metadata and controls

20 lines (16 loc) · 412 Bytes

输入:[['a','b', 'c'],['d', 'e', 'f']] 输出:["ad","ae","af","bd","be","bf","cd","ce","cf"]

let input = [['a','b', 'c'],['d', 'e', 'f']];
let first = input.shift();
let result = input.reduce((memo, current) => {
    let res = [];
    current.forEach(v => {
        memo.forEach(item => {
            res.push(`${item}${v}`)
        });
    });
    return res;
}, first);

console.log(result);