Advertisement
Guest User

Problem 15-Most Frequent Word

a guest
Jul 19th, 2014
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. function findMostFreqWord(text) {
  2. var wordCount = {};
  3. var words = text.split(" ");
  4. for (var i in words) {
  5. var word = words[i];
  6. if (!wordCount[word]) {
  7. wordCount[word] = 0;
  8. }
  9. wordCount[word]++;
  10. }
  11. return wordCount;
  12. }
  13. var text = 'in the middle of the night';
  14. var words = findMostFreqWord(text);
  15.  
  16. for (var i in words) {
  17. console.log(i + ' -> ' + words[i]);
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement