Skip to content

Instantly share code, notes, and snippets.

@ova2
Created January 12, 2025 19:59
Show Gist options
  • Save ova2/36ab0bb08f233ff65db636bf833b369c to your computer and use it in GitHub Desktop.
Save ova2/36ab0bb08f233ff65db636bf833b369c to your computer and use it in GitHub Desktop.
/**
* Generates cartesian product of given iterables.
*/
private* cartesianIterator(items: string[][]): Generator<string[]> {
const remainder = items.length > 1 ? this.cartesianIterator(items.slice(1)) : [[]];
for (const r of remainder) {
for (const h of items.at(0)!) {
yield [h, ...r];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment