logo CodeStepByStep logo

wordCounts

Language/Type: JavaScript objects
Author: Melissa Hovik (on 2018/10/22)

Write a function named wordCounts that takes an array of Strings as a parameter and returns an object mapping each string to its frequency count in the array. For example, if the following array is defined:

let words = ["To", "be", "or", "not", "to", "be"];
        

the call wordCount(words) should return the following:

{ "To" : 1, "be" : 2, "or" : 1, "not" : 1, "to" : 1 }
        

Return the empty object {} if the passed array is empty. You may assume the passed array contains only string values.

Function: Write a JavaScript function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.