documentcloud/underscore — pull request #974 by ansman (2013-02-13 23:01:10+00:00)
Title: Make groupBy accept array indices as the iterator

Background
---
We're using a data format that looks like this:

[['type1', 1234], ['type2', 4321], ...]

I want to group that data by the first element in each sub array.

Why it didn't work
---
Because the iterator defaulted to `_.identity` if the given iterator was
falsy it worked fine with integers != 0 so for example `_.groupBy(data, 1)`
worked fine but `_.groupBy(data, 0)` didn't.

The fix
---
I simply changed so that the iterator is only set to the default value
if the given one is `null` or `undefined`.

Tests
---
I added two simple tests that group a multi dimensional array using 0
and 1 as the iterator.

Backwards compatibility
---
This, of course, breaks backward compatibility but I doubt that anyone
relied on this behaviour.

Discussion
---
I think this solution is better than having to cast the integer to a
string seeing as that is "wrong" (array indices are integers, not
strings), please let me know if you disagree.