MediumArray Methods💻 Output Question

reduce to build a frequency object

💡

Hint

reduce can build any shape — objects, maps, nested structures, not just numbers.

What does this output?

const chars = ['a', 'b', 'a', 'c', 'b', 'a'];
const counts = chars.reduce((acc, c) => {
  acc[c] = (acc[c] || 0) + 1;
  return acc;
}, {});
console.log(counts.a);
console.log(counts.b);

Correct Output

3
2

Why this output?

Explanation: reduce builds a frequency map. a=3, b=2.

Key Insight: reduce can build any shape — objects, maps, nested structures, not just numbers.

More Array Methods Output Questions

Easymap transforms each elementMediumfilter then map chainMediumreduce accumulates to a single valueMediumfind returns first match; filter returns all

Practice predicting output live →

66 output questions with instant feedback

💻 Try Output Quiz