Skip to content

Instantly share code, notes, and snippets.

@schabluk
Created October 10, 2017 07:04
Show Gist options
  • Save schabluk/ec1d440ef09774b9650c6b7c1ee25479 to your computer and use it in GitHub Desktop.
Save schabluk/ec1d440ef09774b9650c6b7c1ee25479 to your computer and use it in GitHub Desktop.
Cartesian of arrays
const f = (a, b) => [].concat(...a.map(d => b.map(e => [].concat(d, e))))
const cartesian = (a, b, ...c) => (b ? cartesian(f(a, b), ...c) : a)
cartesian.apply(this, [["A", "B"], ["C", "D"]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment