Repository URL to install this package:
|
Version:
6.0.4 ▾
|
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var is_1 = require("../../is");
var keysObjOrArray_1 = require("../../util/keysObjOrArray");
var curry_1 = require("../../fp/curry");
/**
* Creates an array of values by running each property of `object`
* or index of `array` thru `iteratee`.
* The iteratee is invoked with three arguments: (value, key, object).
*
* @alias mapAnyVals
* @memberOf loop
* @since 5.0.0
* @category Object
*
* @param obj The object or array to iterate over.
* @param {Function} predicate The function invoked per iteration.
* @param {Object} [result = {}] initial value, accumulated, output
* @return {Array|Object} Returns the new mapped array or object
*
* @example
*
* const square = n => n * n
* map({ 'a': 4, 'b': 8 }, square)
* //=> [16, 64] (iteration order is not guaranteed)
*
*/
function mapObjOrArrayVals(obj, iteratee, result) {
if (result === void 0) { result = {}; }
var isArrayObj = is_1.isArray(obj);
var keys = keysObjOrArray_1.default(obj);
for (var index = 0; index < keys.length; index++) {
var key = isArrayObj ? index : keys[index];
var value = obj[key];
result[key] = iteratee(value, key, obj);
}
return result;
}
exports.default = curry_1.default(2, mapObjOrArrayVals);
//# sourceMappingURL=mapObjOrArrayVals.js.map