The Frequency Counter
Hard+40 XP
Mission Briefing
The Grand Analyzer needs a frequency scan! An array of chaotic data is flowing in, and you must tally up the exact number of occurrences of a specific target element!
The Concept: Logic Complexity
.reduce() is so powerful it can do almost anything. To count elements, you set the initial accumulator to 0, and increment it whenever the current item matches your target!
The Objective
Your function receives an array of items and a target value.
- Use
.reduce()to count how many times thetargetappears in the array. - Return the final count.
01EXAMPLE 1
Input
items = ["A", "B", "A"], target = "A"Output
2Constraints
- Use the .reduce() method for counting.
CoreLogic
JavaScriptSystem handles I/O — write your function only
Loading...
3 Hidden
Input Arguments
items["A","B","A","C"]
target"A"
Expected Output
2
Click RUN to test your solution