all files / src/ mapValues.js

100% Statements 13/13
100% Branches 6/6
100% Functions 3/3
100% Lines 3/3
6 statements, 1 function, 3 branches Ignored     
1 2 3 4 5 6 7 8 9 10      993×          
/**
 * Maps all the values in the given object through the given function and saves them, by key, to a result object
 */
export default function mapValues(obj, fn) {
  return obj ? Object.keys(obj).reduce((accumulator, key) => ({
    ...accumulator,
    [key]: fn(obj[key], key)
  }), {}) : obj;
}