Skip to content

Instantly share code, notes, and snippets.

@eliogalindo92
Created July 20, 2023 23:01
Show Gist options
  • Save eliogalindo92/4bf84222c44f8243c9aee1fcb881513d to your computer and use it in GitHub Desktop.
Save eliogalindo92/4bf84222c44f8243c9aee1fcb881513d to your computer and use it in GitHub Desktop.
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={
labels:Object.keys(counter),
series:Object.values(counter)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment