I have input array as follows. I want to get the unique occurrences name and frequency of those occurrences. I am able to achieve that as shown below.
let input = ["apple", "orange" , "pear", "orange", "apple", "orange"];
input.reduce(function (acc, curr) {
return acc[curr] ? ++acc[curr] : acc[curr] = 1, acc
}, {});
Result:
{ "apple": 2, "orange": 3, "pear": 1}
But I am expecting the result to be in ascending order of frequencies as shown below. Can someone let me know how to achieve it. Also, I have used function
above. Can someone let me know how to use it with arrow operator (ES8 feature)
Expected Result:
{ "orange": 3, "apple": 2, "pear": 1 }