Created
September 25, 2020 13:36
-
-
Save SimonAKing/2f172b9743be9d7cfba6c69428d0fcbf to your computer and use it in GitHub Desktop.
permutation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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