Created
July 20, 2023 23:01
-
-
Save eliogalindo92/4bf84222c44f8243c9aee1fcb881513d to your computer and use it in GitHub Desktop.
Array reducer to compare and reduce objects.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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