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.

  1. Use .reduce() to count how many times the target appears in the array.
  2. Return the final count.

01EXAMPLE 1

Inputitems = ["A", "B", "A"], target = "A"
Output2

Constraints

  • Use the .reduce() method for counting.
CoreLogic
JavaScript
Loading...
3 Hidden

Input Arguments

items["A","B","A","C"]
target"A"

Expected Output

2

Click RUN to test your solution