Skip to content

Instantly share code, notes, and snippets.

View eliogalindo92's full-sized avatar
๐ŸŒ
At work

Elio Galindo Fonseca eliogalindo92

๐ŸŒ
At work
View GitHub Profile
@eliogalindo92
eliogalindo92 / reducer.js
Created July 20, 2023 23:01
Array reducer to compare and reduce objects.
const counter = array.reduce((accumulator, value) => {
if ( accumulator[value.id] ){
accumulator[value.id] += value.total
} else {
accumulator[value.id] = value.total
}
return {...accumulator}
}, []);
const data={