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

Answers

Answer 1
Answer:

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);

   }

}


Related Questions

Write a function in Matlab which takes as input an integer x and as output returns the biggest prime number that is less than or equal to x. For example, if the input is 7, the output would be 7. If the input is 40, the output would be 37. (Reminder: isprime.)
What are the 21St century competencies or skills required in the information society?​
A mobile device user is having problems launching apps and texting. The user touches an app to launch it, but the app icon next to the desired app launches instead. When the user types a text message, every word in the message is misspelled. What is the most likely cause for this behavior?
A) What actions or steps in Excel can you take to rank them from 1st to 10th (4 marks) b) State the specific action(s) or step(s) in Excel that will produce a list/display of those countries with 800 or more medals in total? (4 marks) c) Which type of graph will be suitable for representing only gold medals information? (2 marks) d) In which column(s) might replication have been used? (2 marks) e) What Excel formula can be used to calculate the overall total medals awarded? (3 marks) 14) Write the Excel functions for the following: (5 Marks each) a. Give the total number of medals for Germany and Great Britain. b. Give the average number of silver medals for a European country, c. Sum the Medals Total for Gold for those countries with less than 20 games involvement. d. Search the database (the whole spreadsheet) to find ‘Italy’ and also the corresponding Medals Total.
Develop a program that asks the user to enter a capital for a U.S. state. Upon receiving the user input, the program reports whether the user input is correct. For this application, the 50 states and their capitals are stored in a two-dimensional array in order by state name. Display the current contents of the array then use a bubble sort to sort the content by capital. Next, prompt the user to enter answers for all the state capitals and then display the total correct count. The user's answer is not case-sensitive.

Suppose that a queue is implemented using a circular array of size 12. What is the value of last after the following operations?10 enqueue operations
5 dequeue operations
6 enqueue operations
10 dequeue operations
8 enqueue operations
2 dequeue operations
3 enqueue operations
Last = 10

Answers

Answer:

10

Explanation:

An enqueue operation is a function that adds an element(value) to a queue array. A dequeue operations removes an element from a queue array. Queue arrays follow a first-in-first-out approach, so elements that are first stored in the queue are removed/accessed first(enqueue operations add elements at the rear of the queue array).

The following operations leave 10 elements in the queue of array size 12 after its done:

10 enqueue operations= adds 10 elements

5 dequeue operations= removes 5 elements( 5 elements left in queue)

6 enqueue operations= adds 6 elements(11 elements in queue)

10 dequeue operations= removes 10 elements(1 element left in queue)

8 enqueue operations= adds 8 elements(9 elements in queue)

2 dequeue operations= removes 2 elements(7 elements left in queue)

3 enqueue operations= adds 3 elements(10 elements in queue)

Therefore there are 10 elements in the queue after enqueue and dequeue operations.

A(n) _____ of an class is where the services or behaviors of the class is defined. (Points : 6) operationattribute
class
object
abstract class

Answers

Answer:

Operation the correct answer for the given question.

Explanation:

An operation is a template that is used as a template parameter .An operation defined the services and behaviors of the class .The operation is directly invoked on instance .

Attribute define the property of an entity it is not defined the services and behaviors of the class. so this option is incorrect.

Class is the class of variable of method it is not defined the services and behaviors of the class  so this option is incorrect.

Object are the rub time entity .object are used access the property of a class it is not defined the services and behaviors of the class  so this option is incorrect.

Abstract class is the class which have not full implementation of all the method .it is not defined the services and behaviors of the class  so this option is incorrect.

So the correct answer is operation.

Suppose that a is declared as an int a[99]. Give the contents of the array after the following two statements are executed: for (i = 0; i <99 ; i++) a[i] = a[a[i]];

Answers

Answer:

Each array position holds the position from which the information is going to be retrieved. After the code is run, each position will have the information retrieved from that position.

Explanation:

The best way to solve this problem is working as if we had a very small array. Then we can generalize for the large array.

For example

int a[3];

a[0] = 1; a[1] = 2; a[2] = 0;

for(i = 0; i < 3; i++)

a[i] = a[a[i]];

When i = 0, we have:

a[i] = a[a[i]] = a[a[0]] = a[1] = 2;

When i = 1, we have

a[i] = a[a[i]] = a[a[1]] = a[2] = 0;

When i = 2, we have

a[i] = a[a[i]] = a[a[2]] = a[0] = 1;

Basically, in our small example, each array position holds the index from which we are going to retrieve the information. The same is going to happen in the array of length 99. After the code is run, each position will have the information retrieved from that position

Write a c++ program to find; (I). the perimeter of rectangle.
(ii). the circumference of a circle.

Note:
(1). all the programs must allow the user to make his input .
(2).both programs must have both comment using the single line comment or the multiple line comment to give description to both programs.​

Answers

Answer:

Perimeter:

{ \tt{perimeter = 2(l + w)}}

Circumference:

{ \tt{circumference = 2\pi \: r}}

Justinputthecodesinthenotepad

Expressions Write a console program that prompts the user for 3 double precision floating point values input1, input2, input3. Have the program compute and display the following values. the sum of input1, input2, input3 the average of input1, input2, input3 the log2 of input1 To access the built-in function log2 -- log2(X) computes the base 2 logarithm of X, you need to include the header at the top of your code.

Answers

Answer:

See Explaination

Explanation:

#include <iostream>

#include <cmath>

using namespace std;

int main()

{

float input1, input2, input3;

float sum=0.0, avg, l;

cout<<"enter the value for input1: ";

cin>>input1;

cout<<"enter the value for input2: ";

cin>>input2;

cout<<"enter the value for input3: ";

cin>>input3;

sum=input1+input2+input3;

cout<<"sum of three numbers: "<<sum<<endl;

avg=sum/3;

cout<<"average of three numbers: "<<avg<<endl;

l=log2(input1);

cout<<"log2 value of input1 number: "<<l;

return 0;

}

output:

enter the value for input1: 4

enter the value for input2: 5

enter the value for input3: 6

sum of three numbers: 15

average of three numbers: 5

log2 value of input1 number: 2

In a clustered column chart, the names of each column are part of the ____ series. select one:a. category
b. data
c. label
d. legend

Answers

data.......;...............;.........;......;.
Hello RandomHacker

Answers: In a clustered column chart, the names of each column are part of the data series. 

Hope That helps
-Chris