Adding _.combine method that create all possible combinations from given arrays #1788

Closed
wants to merge 3 commits into
from

Conversation

Projects
None yet
2 participants
@krawaller

This pull request implements a feature I've been missing; it returns all possible combinations of elements from the given arrays. Here's an example:

_.combine([1,2,3],["a","b"],[”foo","bar","baz"]);
// => [ [1,"a","foo"],[1,"a","bar"],[1,"a","baz"],[1,"b","foo"],[1,"b","bar"],[1,"b","baz"],[2,"a","foo"],[2,"a","bar"],[2,"a","baz"],[2,"b","foo"],[2,"b","bar"],[2,"b","baz"]]

Somewhat related to zip but not quite the same.

I was surprised to find no previous discussions on this here or on Underscore-contrib - perhaps it's less useful than I thought? I've used it somewhat often, and as the code to perform it is rather messy, I thought it might be a good fit for inclusion.

@jashkenas

This comment has been minimized.

Show comment
Hide comment
@jashkenas

jashkenas Aug 14, 2014

Owner

Cool idea, but I don't think that's quite useful enough for Underscore. Give Underscore-Contrib a try.

Owner

jashkenas commented Aug 14, 2014

Cool idea, but I don't think that's quite useful enough for Underscore. Give Underscore-Contrib a try.

@krawaller

This comment has been minimized.

Show comment
Hide comment
@krawaller

krawaller Aug 14, 2014

Will do, cheers!

Will do, cheers!

@krawaller krawaller referenced this pull request in documentcloud/underscore-contrib Aug 14, 2014

Merged

Adding _.combine #168

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment