Skip to content

Latest commit

 

History

History
36 lines (24 loc) · 882 Bytes

File metadata and controls

36 lines (24 loc) · 882 Bytes

objects.transform

export function transform *(object(object, func, [accumulator])*

Transform works like reduce, except the accumulator is implicitly returned

Arguments

  1. object (object): input object
  2. func (Function): iteratee function
  3. [accumulator] (Array|object): custom accumulator object *(default {})*

Returns

(*): returns accumulator object after the input object has been iterated over by the function.

Example

const result = objects.transform({ harmony: 2, daft: 4, stripes: 6 }, function(acc, val, key) {
  acc[key] = val + 5 + '_' + idx;
});
console.log(result);
> { harmony: '7_0', daft: '9_1', stripes: '11_2' }