ran npm run tester generate js test files and refactored permuteAll
This commit is contained in:
@ -7,20 +7,18 @@ const permuteAll = (input) => {
|
||||
const result = [];
|
||||
let inputState = input;
|
||||
|
||||
if (typeof input === 'string') inputState = input.split('')
|
||||
if (typeof input === 'string') inputState = input.split('');
|
||||
if (typeof input === 'number') inputState = (input).toString().split('');
|
||||
|
||||
const permute = (arr, m = []) => {
|
||||
if (arr.length === 0) {
|
||||
result.push(m)
|
||||
} else {
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
let curr = arr.slice();
|
||||
let next = curr.splice(i, 1);
|
||||
permute(curr.slice(), m.concat(next))
|
||||
}
|
||||
}
|
||||
}
|
||||
(arr.length === 0)
|
||||
? result.push(m)
|
||||
: arr.forEach((_, i) => {
|
||||
let curr = arr.slice();
|
||||
let next = curr.splice(i, 1);
|
||||
permute(curr.slice(), m.concat(next));
|
||||
});
|
||||
};
|
||||
|
||||
permute(inputState);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user