merger douplicate array

Solutions on MaxInterview for merger douplicate array by the best coders in the world

showing results for - "merger douplicate array"
Valerio
26 Jul 2019
1var array = [{name:"foo1",value:"val1"},{name:"foo1",value:["val2","val3"]},{name:"foo2",value:"val4"}];
2
3function mergeNames (arr) {
4    return _.chain(arr).groupBy('name').mapValues(function (v) {
5        return _.chain(v).pluck('value').flattenDeep();
6    }).value();
7}
8
9console.log(mergeNames(array));
10