I have wrote this simple code that destructures an array of objects to build new arrays from each key. I am learning ES6 and would like to refactor it into one line of code
let candles = [ {
open: 1,
high: 2,
low: 0.5,
close: 1.5,
volume: 200
} ]
const { open, high, low, close, volume } = candles.reduce( ( accumulator, item ) => {
Object.keys( item ).forEach( key => {
accumulator[ key ] = ( accumulator[ key ] || [] ).concat( item[ key ] )
} )
return accumulator
}, {} )