I am struggling with this problem, I have an array:
['a', 'b', 'c', 'a']
I want to have a something like this:
[ {key: 'a', value: 2}, {key: 'b', value: 1}, {key: 'c', value: 1} ]
I managed to get an object from my array using Arrays.reducer:
{a: 2, b: 1, c: 1}
Here is the code I used :
myArray.reduce((occurrences, item) => {
occurrences[item] = (occurrences[item] || 0) + 1;
return occurrences;
}, [])
but I am struggling with transforming it to the array I want.
How would you perform this?