Skip to content

Instantly share code, notes, and snippets.

@Tomotoes
Created September 25, 2020 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tomotoes/2f172b9743be9d7cfba6c69428d0fcbf to your computer and use it in GitHub Desktop.
Save Tomotoes/2f172b9743be9d7cfba6c69428d0fcbf to your computer and use it in GitHub Desktop.
permutation
const permutate = (n, choices = ['A', 'B', 'C', 'D']) => {
const result = []
const recursion = path => {
if (path.length === n) {
result.push(path.join(''))
return
}
choices.forEach(c => { recursion([...path, c]) })
}
recursion([])
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment