Skip to content

Instantly share code, notes, and snippets.

@prontiol
Created May 15, 2019 08:18
Show Gist options
  • Save prontiol/fb63e29d80dbb2fe68ccee25b0db9d07 to your computer and use it in GitHub Desktop.
Save prontiol/fb63e29d80dbb2fe68ccee25b0db9d07 to your computer and use it in GitHub Desktop.
Cartesian Product Object
const product = obj =>
Object.entries(obj).reduce((acc, [key, values]) =>
acc.reduce((acc, item) => [
...acc,
...values.map(value => ({ ...item, [key]: value }))
], []),
[{}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment