Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function findMostFreqWord(text) {
- var wordCount = {};
- var words = text.split(" ");
- for (var i in words) {
- var word = words[i];
- if (!wordCount[word]) {
- wordCount[word] = 0;
- }
- wordCount[word]++;
- }
- return wordCount;
- }
- var text = 'in the middle of the night';
- var words = findMostFreqWord(text);
- for (var i in words) {
- console.log(i + ' -> ' + words[i]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement