1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
shepuryov [24]
3 years ago
8

Implement the function calcWordFrequencies() that uses a single prompt to read a list of words (separated by spaces). Then, the

function outputs those words and their frequencies to the console.
Ex: If the prompt input is:

hey hi Mark hi mark
the console output is:

hey 1
hi 2
Mark 1
hi 2
mark 1
Computers and Technology
1 answer:
Novosadov [1.4K]3 years ago
5 0

Answer:

JavaScript code is given below

Explanation:

function calcWordFrequencies() {

   var words = prompt("Enter the sentence below").split(" ");

   var unique_words = [], freqencies = [], count = 0;

   for (var i = 0; i < words.length; i++) {

       var found = false;

       for (var j = 0; j < count; j++) {

           if (words[i] === unique_words[j]) {

               freqencies[j] = freqencies[j] + 1;

               found = true;

           }

       }

       if (!found) {

           unique_words[count] = words[i];

           freqencies[count] = 1;

           count++;

       }

   }

   for (var i = 0; i < words.length; i++) {

       var result = 0;

       for (var j = 0; j < count; j++) {

           if (words[i] === unique_words[j]) {

               result = freqencies[j];

               break;

           }

       }

       console.log(words[i] + " " + result);

   }

}

You might be interested in
A large amount of data is stored in secondary storage is it true<br>​
Mice21 [21]
Since it’s more cost efficient, it’s better to store more data in the secondary storage. Yes true!
6 0
3 years ago
Read 2 more answers
JAVA
Umnica [9.8K]

import java.util.Scanner;

public class JavaApplication58 {

   

   public static void main(String[] args) {

       Scanner scan = new Scanner(System.in);

       System.out.println("Enter a positive integer:");

       String num = scan.nextLine();

       for (int i = num.length()-1; i >=0; i--){

           System.out.println(num.charAt(i));

       }

       

   }

   

}

I hope this helps!

5 0
3 years ago
Describe the difference between Global knowledge and personal idea. Why is it important to give credit to others by citing their
sergejj [24]

Global knowledge is like common sense, people know these things, but their may be someone else with the same idea. One person can come up with the idea but their is also another with same so don't give someone to much credit.

7 0
3 years ago
Which of the given original work is protected by the copyright law
andreyandreev [35.5K]
BMW is my desion u cant copy write alot of things like books movies logos
7 0
3 years ago
Read 2 more answers
4.5 Code Practice
Alex787 [66]

Answer:

The answer to this question is given below in the explanation section.

Explanation:

This program is written in C++.

                                                                         

#include <iostream>

using namespace std;

int main()

{

   

   string word;// variable for taking user input

   int cond;// to set condition true if user preses the stop and exit from loop

   

   cout<<"Enter word: \n";

   cin>>word;

   do// start while loop

   {

       

       

       if(word=="stop" || word =="STOP" || word == "Stop")// if user enter word stop, then program exit

       {

       cond=0;

       

       }

       else//otherwise loop continue

       {

           cout<<" You Entered "+ word +"\n";

           cout<<"Enter word: \n";

           cin>>word;

           cond=1;

       }

   }  

   while(cond == 1);// if user don't enter word "stop" loop run continuesly.  

   cout<<"Program exit";

   

   return 0;

}

5 0
3 years ago
Other questions:
  • Assume that
    7·1 answer
  • Which method allows a computer to react accordingly when it requests data from a server and the server takes too long to respond
    5·1 answer
  • Write a function named get_my_age that returns your age as an int (this is YOUR age, so if you were 21 you would return the numb
    11·1 answer
  • Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follo
    5·1 answer
  • (d) What other services beside cloud-based software may be provided by Internet hosts?[1]
    11·1 answer
  • 9. Which is an example of a function?<br>(1 Point)<br>=A1 +A2<br>=SUM(A1:A3)<br>=ADD(A1:A3)​
    14·2 answers
  • Explain the characteristics of a first generation computer​
    8·1 answer
  • Which one is better AMD Ryzen 5 Or Nvidia Gtx 2080 ti
    6·1 answer
  • Examples of structures that can store homogeneous data element​
    14·1 answer
  • As a member of the help desk administration team, you've been assigned to update the driver for the network adapter that is inst
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!