The Master Frequency Map

HardAcc. 58.4%
+100 XP 50

The Grand Finalé: Associative Mastery

You have counted "apples" before. Now, you must count everything.

The Assignment

Your function receives an array items.

  1. Create a "conceptual object" named counts.
  2. Iterate through every item in the array.
  3. If the item is not in your object yet, initialize it to 0.
  4. Increment the value for that item in your object.
  5. After the loop, print the keys and their counts in the format: Item: Count.

01EXAMPLE 1

Input["apple", "apple", "banana"]
Outputapple: 2 banana: 1

Explanation: Counts all items in one pass.

Constraints

  • Use a single for loop (O(n)).
  • Use an object as a frequency map.
ArraysObjectsMastery
JavaScript
Loading...
2 Hidden

Input Arguments

items["apple","banana","apple"]

Expected Output

apple: 2
banana: 1

Click RUN to test your solution