![](https://img2018.cnblogs.com/blog/1853166/202001/1853166-20200126203546947-864357975.png) ![](https://img2018.cnblogs.com/blog/1853166/202001/18531... ...
export default (str, words) => {
// 保存結果
let result = []
// 記錄數組的長度,做邊界條件計算
let num = words.length
// 遞歸函數體
let range = (r, _arr) => {
if (r.length === num) {
result.push(r)
} else {
_arr.forEach((item, idx) => {
let tmp = [].concat(_arr)
tmp.splice(idx, 1)
range(r.concat(item), tmp)
})
}
}
range([], words)
// [0, 9, -1] filter 之後[0,9]
return result.map(item => {
return str.indexOf(item.join(''))
}).filter(item => item !== -1).sort()
}