I'm interested in utilizing the sort method mentioned in the link but I am facing
{
"CYLINDER": 2986,
"HYDRAULIC": 1421,
"JACKS": 84,
"INSTALLATION": 119,
"REAR": 61,
"JACK": 334,
"TUBE": 1,
"FEED": 114,
"ASSEMBLY": 326,
"DCS": 2,
"TOWER": 65,
"RAISING": 8,
"BREAKOUT": 6,
}
I have devised this function that groups similar strings together and assigns a count for each (shown as values in the key-value pairs above)
function calculateDuplicateOccurrences(wordArray) {
const countedWords = wordArray.reduce(function(allWords, word) {
if (word in allWords) {
allWords[word]++;
}
else {
allWords[word] = 1;
}
return allWords;
}, {});
return countedWords;
}
Despite my efforts on Google and Stackoverflow, I haven't come across a solution to sort by value when the keys are not unique. Any suggestions on how to address this issue?
The desired outcome looks like this:
{
"TUBE": 1,
"DCS": 2,
"BREAKOUT": 6,
"RAISING": 8,
"REAR": 61,
"TOWER": 65,
"JACKS": 84,
"FEED": 114,
"INSTALLATION": 119,
"ASSEMBLY": 326,
"JACK": 334,
"HYDRAULIC": 1421,
"CYLINDER": 2986
}