0

I Have this problem and honestly have no idea where or how to start this, can anyone give me an idea or help?

Write a JavaScript program to calculate the statistics of words in a web page. When running the program in a web page, the script should output all words in descending order of their number of occurrences. The number of occurrences should be displayed along with the words. When two or more words have the same number of occurrences, order them alphabetically. The output should show up as a new web page when the program runs. HTML tags and scripts inside web pages should not be considered as words by the program. The program should run in all web pages, not just one page.

I got python coding for it, but not sure for java, also how to order by descending order

import re

def addWord(token, frequencies):
    count = 0
    word = ''.join(token)
    if word in frequencies:
        count = frequencies[word]
    frequencies[word] = count + 1

def getWordFrequencies(text):
    pattern = re.compile('\w')
    frequencies = {}
    token = []
    
    for c in text:
        if pattern.search(c):
            token.append(c)
        elif token:
            addWord(token, frequencies)
            token = []
    
    if token:
        addWord(token, frequencies)

    return frequencies



wordCount = raw_input("Please Enter text here: ")

result = getWordFrequencies(wordCount)

for word, freq in result.iteritems():
    print freq, "\t", word
2
Contributors
1
Reply
3
Views
7 Years
Discussion Span
Last Post by fxm
0

how to start
...
not sure for java

Why not look up the javascript commands and functions that match each python command and function?

BTW: javascript != java.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.