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
The main file type used when saving a powerpoint presentation is the?
weeeeeb [17]
I am pretty sure it is the XML format
6 0
3 years ago
5. Bits are sent over a communications channel in packets of 12. (a) If the probability of a bit being corrupted over this chann
user100 [1]

Answer:

0.889

Explanation:

7 0
4 years ago
Write a program that: Takes the list lotsOfNumbers and uses a loop to find the sum of all of the odd numbers in the list (hint:
Alika [10]

Answer:

Following are the code to this question:

#include <iostream>//defining header file

using namespace std;

int main()//defining main method

{

int x[]={2,3,4,6,7,8,9,1,11,12};//defining 1-D array and assign value

int i,sum=0;//defining integer variable

for(i=0;i<10;i++)//defining loop for count value

{

   if(x[i]%2==1)//defining if block to check odd value

   {

       sum=sum+x[i];//add value in sum variable

   }

}

cout<<sum;//print sum

return 0;

}

Output:

31

Explanation:

In the above-given program, an integer array "x" is declared that holds some integer values, and in the next line two integer variable "i and sum" is defined which is used to calculate the value.

In the next line, a for loop is declared, that counts all array value, and it uses the if block to check the odd value and add all the value into the sum variable.

5 0
3 years ago
Hi, I'm having a bit of trouble with figuring out which thing is supposed to go with which. If someone could help, that would be
Pavel [41]

Answer:

Formatting Bar

Function

Rows

Sum

Cell Range

Formula

Average

Ctrl + Z

Right Mouse Click

Columns

4 0
3 years ago
How often should you typically monitor your checking account? Yearly Daily Every three months Monthly
Maslowich
I’d say monthly. It probably wouldn’t kill you to do it every three months though.
7 0
3 years ago
Read 2 more answers
Other questions:
  • It is appropriate to leave sections of an application blank ?<br><br><br><br> True or False
    7·1 answer
  • Write a C program that reads a string containing text and nonnegative numbers from the user and prints out the numbers contained
    6·1 answer
  • How do humans acquire voltage in their bodies
    8·1 answer
  • Why should the ISO be adjusted when taking a picture of a child blowing out candles in a darkened room?
    10·1 answer
  • Does the brain play a role in smartphone addiction
    7·2 answers
  • Which of the following is not a property of a constructor?A. The name of a constructor can be chosen by the programmerB. A const
    11·1 answer
  • What problems have arisen regarding use of the Internet for global business transactions, and how are they being resolved?
    15·1 answer
  • Create a method to search an un-ordered array of integers for a value, if the value is found return the index of its position in
    10·1 answer
  • Given two integers as user inputs that represent the number of drinks to buy and the number of bottles to restock, create a Vend
    10·1 answer
  • No links it’s just a normal question about iPhones.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!