javascript program to sort words in text by number of occurrences