js 输入一个数组 输出该数组的所有排列组合
Input: [1,2,3]
Output: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
function calculate (nums) { let result = [];
let go = function (currentArr) {
if(currentArr.length === nums.length){
result.push(currentArr);
return;
}
nums.forEach(v => {
if(!currentArr.includes(v)){
go([...currentArr, v]);
}
})
}
go([])
return result
}