I have the following method that gets the word frequency based on some input text:
function getWordFrequency(lowerCaseArray) {
var wordFrequency = {};
$.each(lowerCaseArray, function(ix, word) {
// skip empty results
if (!word.length) {
return;
}
// add word to wordFrequency
if (!wordFrequency[word]) {
wordFrequency[word] = 0;
}
wordFrequency[word]++;
});
return wordFrequency;
}
However, I would like to return the frequency of words on a descending order, i.e.
cats => 20
dogs => 19
frog => 17
humans => 10
Currently, my algorithm returns in the order in which the input words appear.
Array.prototype.sortmethod.