time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

mapKeys.js (1097B)


      1 var baseAssignValue = require('./_baseAssignValue'),
      2     baseForOwn = require('./_baseForOwn'),
      3     baseIteratee = require('./_baseIteratee');
      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 module.exports = mapKeys;