in groupBy, also pass index to iterator.

This commit is contained in:
Andrei
2011-05-05 14:43:28 -04:00
parent b75e48c057
commit 1681d25063

View File

@@ -254,8 +254,8 @@
// Groups the object's values by a criterion produced by an iterator
_.groupBy = function(obj, iterator) {
var result = {};
each(obj, function(value) {
var key = iterator(value);
each(obj, function(value, index) {
var key = iterator(value, index);
(result[key] || (result[key] = [])).push(value)
});
return result;