main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Rev | Line | |
---|
[d565449] | 1 | import baseAssignValue from './_baseAssignValue.js';
|
---|
| 2 | import baseForOwn from './_baseForOwn.js';
|
---|
| 3 | import baseIteratee from './_baseIteratee.js';
|
---|
| 4 |
|
---|
| 5 | /**
|
---|
| 6 | * The opposite of `_.mapValues`; this method creates an object with the
|
---|
| 7 | * same values as `object` and keys generated by running each own enumerable
|
---|
| 8 | * string keyed property of `object` thru `iteratee`. The iteratee is invoked
|
---|
| 9 | * with three arguments: (value, key, object).
|
---|
| 10 | *
|
---|
| 11 | * @static
|
---|
| 12 | * @memberOf _
|
---|
| 13 | * @since 3.8.0
|
---|
| 14 | * @category Object
|
---|
| 15 | * @param {Object} object The object to iterate over.
|
---|
| 16 | * @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
---|
| 17 | * @returns {Object} Returns the new mapped object.
|
---|
| 18 | * @see _.mapValues
|
---|
| 19 | * @example
|
---|
| 20 | *
|
---|
| 21 | * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
|
---|
| 22 | * return key + value;
|
---|
| 23 | * });
|
---|
| 24 | * // => { 'a1': 1, 'b2': 2 }
|
---|
| 25 | */
|
---|
| 26 | function mapKeys(object, iteratee) {
|
---|
| 27 | var result = {};
|
---|
| 28 | iteratee = baseIteratee(iteratee, 3);
|
---|
| 29 |
|
---|
| 30 | baseForOwn(object, function(value, key, object) {
|
---|
| 31 | baseAssignValue(result, iteratee(value, key, object), value);
|
---|
| 32 | });
|
---|
| 33 | return result;
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | export default mapKeys;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.