Skip to content

Instantly share code, notes, and snippets.

@pyldin601
Created March 10, 2020 14:30
Show Gist options
  • Save pyldin601/515f4cfd140921b7ed85e9153c07e038 to your computer and use it in GitHub Desktop.
Save pyldin601/515f4cfd140921b7ed85e9153c07e038 to your computer and use it in GitHub Desktop.
export function* iterateOverCombinedItems(items) {
if (items.length === 0) {
return
}
const [h, ...tail] = items
const heads = Array.isArray(h) ? h : [h]
for (const head of heads) {
if (tail.length > 0) {
for (const subResult of iterateOverCombinedItems(tail)) {
yield [head, ...subResult]
}
} else {
yield [head]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment