1 var baseAssignValue = require('./_baseAssignValue'),
2 createAggregator = require('./_createAggregator');
5 * Creates an object composed of keys generated from the results of running
6 * each element of `collection` thru `iteratee`. The corresponding value of
7 * each key is the last element responsible for generating the key. The
8 * iteratee is invoked with one argument: (value).
13 * @category Collection
14 * @param {Array|Object} collection The collection to iterate over.
15 * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
16 * @returns {Object} Returns the composed aggregate object.
20 * { 'dir': 'left', 'code': 97 },
21 * { 'dir': 'right', 'code': 100 }
24 * _.keyBy(array, function(o) {
25 * return String.fromCharCode(o.code);
27 * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
29 * _.keyBy(array, 'dir');
30 * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
32 var keyBy = createAggregator(function(result, value, key) {
33 baseAssignValue(result, key, value);
36 module.exports = keyBy;