Skip to content

Instantly share code, notes, and snippets.

@orrgal1
Created December 31, 2018 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orrgal1/9cefadc127af60855c365f4de2fde89c to your computer and use it in GitHub Desktop.
Save orrgal1/9cefadc127af60855c365f4de2fde89c to your computer and use it in GitHub Desktop.
Productable: a tiny function to create product of arrays
function Productable(arr) {
const self = {
array: arr.map(e => Array.isArray(e) ? e : [e]),
product: (otherArr) => {
const newArray = [];
self.array.forEach(e => {
otherArr.forEach(oe => {
newArray.push([...e, oe]);
});
});
return new Productable(newArray);
},
toArray: () => self.array
};
return self;
}
module.exports = {
Productable
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment