Transform an object into another object structure I've got such an input object, which I should modify in order to use it with some charts library.

const input = {
  foo: {
    bar: 'biz',
  },
  statistic: {
    "2019-11": {
      A: 11,
      B: 11,
      C: 11,
      D: 11,
      E: 11,
    },
    "2019-12": {
      A: 12,
      B: 12,
      C: 12,
      D: 12,
      E: 12,
    },
    ....
  }
};


My library expects an input like this:

[ 
  { subject: 'A', '2019-11': 11, '2019-12': 12 },
  { subject: 'B', '2019-11': 11, '2019-12': 12 },
  { subject: 'C', '2019-11': 11, '2019-12': 12 },
  { subject: 'D', '2019-11': 11, '2019-12': 12 },
  { subject: 'E', '2019-11': 11, '2019-12': 12 } 
]


And this is my current solution:

const transform = arg =&gt; {
  const keys = ['A', 'B', 'C', 'D', 'E'];
  return _.map(keys, key =&gt; {
    const data = _.reduce(arg.statistic, (result, value, k) =&gt; {
      result[k] = value[key];
      return result;
    }, {});
    return {
      subject: key,
      ...data
    }
  });
}


Any improvements would be very welcome!
So you have five data series here right (A through E)?  What happens when you have 4 or 6 data series?  Do you really want to rewrite your code?

Also, unless you have some reason to do so, lodash seems kind of unnecessary for these sort of simple data transforms these days.  I am guessing using ES6 Array.map, Array.reduce and similar would do the same exact thing while also yielding a more fluent, readable style,