Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Adding _.combine #168
This pull request implements a feature I've been missing; it returns an array of all possible combinations using one element each from the given arrays.
Each element in the return array with therefore contain as many elements as you fed
Here's an example:
This was deemed not quite useful enough for Underscore proper, but might qualify for _.contrib? I use it somewhat often, and as doing it "manually" is messy and verbose, a helper for this functionality really cleans up the code.
added a commit
this pull request
Aug 14, 2014
Had a thought; without reading the specifics, someone might expect a function named
Perhaps make the function act that way when called with an array and an integer? Or maybe give my function a different name (
I think I figured out a neat solution to the API woes; how about changing the signature to allow an optional last argument
That way it covers the (presumably) common use case where we want combinations from a single array.
It would also makes working with multiple arrays more flexible. And letting
Downside is it kills the otherwise excellent (I facepalmed, should have thought of that myself) naming suggestion from @berrytj . Any ideas what to call this new hybrid between cartesian product and combinations?