Created
December 31, 2018 13:44
-
-
Save orrgal1/9cefadc127af60855c365f4de2fde89c to your computer and use it in GitHub Desktop.
Productable: a tiny function to create product of arrays
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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