mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-02 08:07:50 +00:00
Bump to v4.0.0.
This commit is contained in:
39
mapValues.js
Normal file
39
mapValues.js
Normal file
@@ -0,0 +1,39 @@
|
||||
import baseForOwn from './internal/baseForOwn';
|
||||
import baseIteratee from './internal/baseIteratee';
|
||||
|
||||
/**
|
||||
* Creates an object with the same keys as `object` and values generated by
|
||||
* running each own enumerable property of `object` through `iteratee`. The
|
||||
* iteratee function is invoked with three arguments: (value, key, object).
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Object
|
||||
* @param {Object} object The object to iterate over.
|
||||
* @param {Function|Object|string} [iteratee=_.identity] The function invoked per iteration.
|
||||
* @returns {Object} Returns the new mapped object.
|
||||
* @example
|
||||
*
|
||||
* var users = {
|
||||
* 'fred': { 'user': 'fred', 'age': 40 },
|
||||
* 'pebbles': { 'user': 'pebbles', 'age': 1 }
|
||||
* };
|
||||
*
|
||||
* _.mapValues(users, function(o) { return o.age; });
|
||||
* // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
|
||||
*
|
||||
* // using the `_.property` iteratee shorthand
|
||||
* _.mapValues(users, 'age');
|
||||
* // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
|
||||
*/
|
||||
function mapValues(object, iteratee) {
|
||||
var result = {};
|
||||
iteratee = baseIteratee(iteratee, 3);
|
||||
|
||||
baseForOwn(object, function(value, key, object) {
|
||||
result[key] = iteratee(value, key, object);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
export default mapValues;
|
||||
Reference in New Issue
Block a user