Created
October 28, 2024 20:31
-
-
Save kalisjoshua/38d094fda2c1573da703140e296f4bc0 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
// SOURCE: https://gist.github.com/ssippe/1f92625532eef28be6974f898efb23ef?permalink_comment_id=4612830#gistcomment-4612830 | |
export function cartesian<T>(...all: T[][]): T[][] { | |
return all.reduce<T[][]>( | |
(results, entries) => | |
results | |
.map((result) => entries.map((entry) => result.concat([entry]))) | |
.reduce((sub, res) => sub.concat(res), []), | |
[[]], | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment