Created
March 10, 2020 14:30
-
-
Save pyldin601/515f4cfd140921b7ed85e9153c07e038 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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