Skip to content

Instantly share code, notes, and snippets.

@jkantr
Last active April 23, 2017 19:28
Show Gist options
  • Save jkantr/0bd39a9d4feec00cee3835926649d838 to your computer and use it in GitHub Desktop.
Save jkantr/0bd39a9d4feec00cee3835926649d838 to your computer and use it in GitHub Desktop.
Cartesian product of N arrays in Javascript
const cartesianProduct = (...args) => args.reduce((a, b) => a.map(x => b.map(y => x.concat([y]))).reduce((acc, t) => acc.concat(t), []) , [[]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment