N
Size: a a a
N
МК
j
N
a
function myFunction(payload) {
const hash = payload.reduce((acc, cv) => {
if ('undefined' != typeof acc[cv.id]) {
acc[cv.id] += cv.count;
} else {
acc[cv.id] = cv.count;
}
return acc;
}, {});
return Object.entries(hash).map(
([k, v]) => ({ id: k, count: v })
);
}
var result = myFunction([
{ id: 'a1', count: 2, title: 'First' },
{ id: 'a1', count: 1, title: 'First' },
{ id: 'b1', count: 3, title: 'Second' },
{ id: 'c1', count: 2, title: 'Third' },
{ id: 'c1', count: 3, title: 'Third' },
]);
console.dir(result);
D
const fn = (arr) => {
const hash = {}
arr.forEach(({title, ...obj}) => {
hash[obj.id] ? hash[obj.id].count += obj.count : hash[obj.id] = obj;
})
return Object.values(hash)
}
a
const fn = (arr) => {
const hash = {}
arr.forEach(({title, ...obj}) => {
hash[obj.id] ? hash[obj.id].count += obj.count : hash[obj.id] = obj;
})
return Object.values(hash)
}
const fn = () => {
const fn = (arr) => {
D
const fn = () => {
const fn = (arr) => {
a
N
function myFunction(payload) {
const hash = payload.reduce((acc, cv) => {
if ('undefined' != typeof acc[cv.id]) {
acc[cv.id] += cv.count;
} else {
acc[cv.id] = cv.count;
}
return acc;
}, {});
return Object.entries(hash).map(
([k, v]) => ({ id: k, count: v })
);
}
var result = myFunction([
{ id: 'a1', count: 2, title: 'First' },
{ id: 'a1', count: 1, title: 'First' },
{ id: 'b1', count: 3, title: 'Second' },
{ id: 'c1', count: 2, title: 'Third' },
{ id: 'c1', count: 3, title: 'Third' },
]);
console.dir(result);
N
const fn = (arr) => {
const hash = {}
arr.forEach(({title, ...obj}) => {
hash[obj.id] ? hash[obj.id].count += obj.count : hash[obj.id] = obj;
})
return Object.values(hash)
}
N
МК
DP
DP
AK
МК
МК