Transforms values of an object with an unary function.
Transforms values of an object with an unary function.
The transformation works on the values of each own, enumerable property of the given object. Inherited and non-enumerable properties are ignored by this function.
const mapValues = require('folktale/core/object/map-values');
const pair = { x: 10, y: 20 };
mapValues(pair, x => x * 2);
// ==> { x: 20, y: 40 }
mapValues
will not preserve the shape of the original object.
It treats objects as plain maps from String to some value, and
ignores things like prototypical delegation, symbols, and non-enumerable
properties.
Conveniently transforms values in an object using the This-Binding syntax.
(object, transformation) => {
const keys = Object.keys(object);
const result = {};
for (let i = 0; i < keys.length; ++i) {
const key = keys[i];
result[key] = transformation(object[key]);
}
return result;
}