Skip to content

Instantly share code, notes, and snippets.

View kalisjoshua's full-sized avatar

Joshua T Kalis kalisjoshua

View GitHub Profile
// 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), []),
[[]],
);
}