Skip to content

Latest commit

 

History

History
36 lines (24 loc) · 819 Bytes

transform.md

File metadata and controls

36 lines (24 loc) · 819 Bytes

objects.transform

transform(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

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' }