Skip to content

Instantly share code, notes, and snippets.

@ChathuraGH
Created December 3, 2023 18:52
Show Gist options
  • Save ChathuraGH/b91cfb9f986ba1cc992ad4f59c6d5ee0 to your computer and use it in GitHub Desktop.
Save ChathuraGH/b91cfb9f986ba1cc992ad4f59c6d5ee0 to your computer and use it in GitHub Desktop.
Dictionary permutation generator
// 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