Is there a way to efficiently convert an array of elements into an object with key value pairs representing element frequencies? For example, given an array:
var array = ['a','a','a','b','b','c','d','d','d','d',]
I want to transform it into an object like this:
obj = [{ element: 'a', frequency: 3},
{ element: 'b', frequency: 2},
{ element: 'c', frequency: 1},
{ element: 'd', frequency: 4}]
Instead of the above format, I currently have a solution that provides the following output:
obj = { a : 3, b : 2, c : 1, d : 4 }