面试题:找组合

试题:找出[[1, 2, 3], ['a', 'b', 'c'], ['@', '#', '%']] 的所有组合,规则如下:1a@1a#1a%1b@1b#...

var arr = [[1, 2, 3], ['a', 'b', 'c'], ['@', '#', '%']]

function dfs (index, path) {
    if (index === arr.length) {
        console.log(path)
        return
    }

    var i, len
    for (i = 0, len = arr[index].length; i < len; i++) {
        dfs(index + 1, path + arr[index][i])
    }
}

dfs(0, '')

你可能感兴趣的:(面试题:找组合)