* Creates a function that aggregates a collection, creating an accumulator * object composed from the results of running each element in the collection * through an iteratee. * * **Note:** This function is used to create `_.countBy`, `_.groupBy`, `_.indexBy`, * and `_.partit
(setter, initializer)
| 4548 | * @returns {Function} Returns the new aggregator function. |
| 4549 | */ |
| 4550 | function createAggregator(setter, initializer) { |
| 4551 | return function(collection, iteratee, thisArg) { |
| 4552 | var result = initializer ? initializer() : {}; |
| 4553 | iteratee = getCallback(iteratee, thisArg, 3); |
| 4554 | |
| 4555 | if (isArray(collection)) { |
| 4556 | var index = -1, |
| 4557 | length = collection.length; |
| 4558 | |
| 4559 | while (++index < length) { |
| 4560 | var value = collection[index]; |
| 4561 | setter(result, value, iteratee(value, index, collection), collection); |
| 4562 | } |
| 4563 | } else { |
| 4564 | baseEach(collection, function(value, key, collection) { |
| 4565 | setter(result, value, iteratee(value, key, collection), collection); |
| 4566 | }); |
| 4567 | } |
| 4568 | return result; |
| 4569 | }; |
| 4570 | } |
| 4571 | |
| 4572 | /** |
| 4573 | * Creates a function that assigns properties of source object(s) to a given |
no test coverage detected