Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.