const permute = function (nums) {
const result = [];
const findPermutations = (freeNums, fixedNums = []) => {
if (freeNums.length === 1) {
result.push(fixedNums.concat(freeNums));
} else {
for (let i = 0; i < freeNums.length; i++) {
const nextFreeNums = [...freeNums];
const nextFixedNum = nextFreeNums.splice(i, 1);
findPermutations(nextFreeNums, fixedNums.concat(nextFixedNum));
}
}
};
findPermutations(nums);
return result;
};
console.log(permute("abc"));
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)