I'm currently exploring ways to efficiently aggregate all items within a collection.
Specifically, I am interested in identifying the most effective method using Lodash to group this set of objects by each of their keys (in depth), assuming that the values are neither sub-objects nor arrays.
let input = [{
food: {
fruits: {
apples: 2,
bananas: 3,
peaches: 'square',
citrus: [100,200,300]
},
meat: {
beef: 1000,
chicken: 2000
}
}
},{
food: {
fruits: {
apples: 4,
bananas: 5,
peaches: 'triangle',
citrus: [101,201,301]
},
meat: {
beef: 1001,
chicken: 2001
}
}
}];
let output = {
food: {
fruits: {
apples: [2,4],
bananas: [3,5],
peaches: ['square', 'triangle'],
citrus: [[100,101],[200,201],[300,301]]
},
meat: {
beef: [1000, 1001],
chicken: [2000, 2001]
}
}
}
It appears that there isn't a specific function available in the API for this task. I am curious if there is a way to achieve this in one iteration without needing to loop through the initial collection multiple times.