Created
December 3, 2023 18:52
-
-
Save ChathuraGH/b91cfb9f986ba1cc992ad4f59c6d5ee0 to your computer and use it in GitHub Desktop.
Dictionary permutation generator
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
// console.log([...permutate(['1', '2', '3'], 2)]) | |
// console.log([...permutate(['1', '2', '3'], 3)]) | |
function* permutate(items, count) { | |
yield* req([]) | |
function* req(array) { | |
if (array.length == count) { | |
yield array.join('') | |
return | |
} | |
for (const item of items) { | |
yield* req(array.concat(item)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment