老师好! 我想问一个问题,如下就像电话号码组合这里算不算是一个闭包?
export default (str) => {
if (str.length < 1) return []
let map = [’’, 1, ‘abc’, ‘def’, ‘ghi’, ‘jkl’, ‘mno’, ‘pqrs’, ‘tuv’, ‘wxyz’]
if (str.length < 2) return map[str].split(’’)
let num = str.split(’’)
let code = []
num.forEach(item => {
if (map[item]) {
code.push(map[item])
}
})
let comb = (arr) => {
let tmp = []
for (let i = 0, il = arr[0].length; i < il; i++) {
for (let j = 0, jl = arr[1].length; j < jl; j++) {
tmp.push(${arr[0][i]}${arr[1][j]}
)
}
}
arr.splice(0, 2, tmp)
if (arr.length > 1) {
comb(arr)
} else {
return tmp
}
return arr[0]
}
return comb(code)
}