Skip to content

Instantly share code, notes, and snippets.

@dobleuber
Created July 29, 2020 03:34
Show Gist options
  • Save dobleuber/a094cc71a66c772381dd37a6119e2936 to your computer and use it in GitHub Desktop.
Save dobleuber/a094cc71a66c772381dd37a6119e2936 to your computer and use it in GitHub Desktop.
Hallar las permutaciones de un string.
const stringPermutations = str => {
if (str.length === 1) return [str];
return str
.split('')
.reduce(
(acc, letter, i) =>
acc.concat(
stringPermutations(str.slice(0, i) + str.slice(i + 1)
)
.map(val => letter + val))
,[]
);
};
console.log('Result', stringPermutations('abcde'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment