What an elegant way - purely functional, ideal - to convert (reduce?) This array:
var in = [ { a: 1, b: 'x', c: 'foo' }, { a: 1, b: 'y', c: 'goo' }, { a: 2, b: 'x', c: 'hoo' }, { a: 2, b: 'y', c: 'joo' } ]
In it:
var out = [ { a: 1, x: 'foo', y: 'goo' }, { a: 2, x: 'hoo', y: 'joo' } ]
The logic is that all elements should be combined based on their property a , and all properties b and c are key / value pairs, respectively, which should be combined into one object based on their common a value.
source share