jquery/jquery — pull request #933 by onyxrev (2012-09-25 08:00:20+00:00)
Title: Add $.reduce utility as compliment to $.map

I've always wanted a reduce/inject method for jQuery to compliment the map method. I can't count how many times I've used temp vars and $.each just to build an indexed object from an array. I assume others have as well, but I imagine there's resistance to any bloat in the core, which I do understand.

Anyway... here's a $.reduce implementation.

Some examples:

```
var list_of_objects = [
{id: "1332", text: "one", visible: true},
{id: "4321", text: "two", visible: false},
{id: "9292", text: "three", visible: true}
];

// params are the source, an accumulator that provides the
// initial value, and an iterator function
$.reduce(list_of_objects, {}, function(output, i, obj){
output[obj.id] = obj;
return output;
});

// produces an object of objects indexed by the id
```

```
$.reduce([1,2,3,4], 0, function(sum, i, num){
sum = sum + num;
return sum;
});

// produces 10
```