main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1.2 KB
|
Rev | Line | |
---|
[d565449] | 1 | import baseAssignValue from './_baseAssignValue.js';
|
---|
| 2 | import createAggregator from './_createAggregator.js';
|
---|
| 3 |
|
---|
| 4 | /**
|
---|
| 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).
|
---|
| 9 | *
|
---|
| 10 | * @static
|
---|
| 11 | * @memberOf _
|
---|
| 12 | * @since 4.0.0
|
---|
| 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.
|
---|
| 17 | * @example
|
---|
| 18 | *
|
---|
| 19 | * var array = [
|
---|
| 20 | * { 'dir': 'left', 'code': 97 },
|
---|
| 21 | * { 'dir': 'right', 'code': 100 }
|
---|
| 22 | * ];
|
---|
| 23 | *
|
---|
| 24 | * _.keyBy(array, function(o) {
|
---|
| 25 | * return String.fromCharCode(o.code);
|
---|
| 26 | * });
|
---|
| 27 | * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
|
---|
| 28 | *
|
---|
| 29 | * _.keyBy(array, 'dir');
|
---|
| 30 | * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
|
---|
| 31 | */
|
---|
| 32 | var keyBy = createAggregator(function(result, value, key) {
|
---|
| 33 | baseAssignValue(result, key, value);
|
---|
| 34 | });
|
---|
| 35 |
|
---|
| 36 | export default keyBy;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.