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.
- Create a "conceptual object" named
counts. - Iterate through every
itemin the array. - If the item is not in your object yet, initialize it to 0.
- Increment the value for that item in your object.
- After the loop, print the keys and their counts in the format:
Item: Count.
01EXAMPLE 1
Input
["apple", "apple", "banana"]Output
apple: 2
banana: 1Explanation: Counts all items in one pass.
Constraints
- Use a single for loop (O(n)).
- Use an object as a frequency map.
ArraysObjectsMastery
JavaScriptSystem handles I/O — write your function only
Loading...
2 Hidden
Input Arguments
items["apple","banana","apple"]
Expected Output
apple: 2 banana: 1
Click RUN to test your solution