LeetCode/exercises/rec-permute/nodejs/index.js

19 lines
462 B
JavaScript
Raw Normal View History

const RecPermute = (soFar, rest) => {
if (rest.length === 0) {
console.log('result', soFar);
console.log('\n\n');
} else {
for (let i = 0; i < rest.length; i++) {
const remaining = rest.substring(0,i) + rest.substring(i+1);
console.log('r', remaining)
console.log('R', rest);
console.log('SF', soFar);
console.log('------');
RecPermute(soFar + rest[i], remaining);
}
}
};
x = 'abc';
RecPermute('', x);