Question 1
IntermediateVariables, Types, and Collections · Array Data Manipulation
A developer is building a financial dashboard that processes transaction lists. They need to calculate the total balance from an array of transaction objects, where each object contains a type ('credit' or 'debit') and an amount.
Which array method and implementation best achieves this single-value result?
Answer and explanation
Correct answer: C
The reduce() method is specifically designed to transform an array into a single value (the accumulator) by applying a function to each element. map() creates a new array of the same length, which is not the goal here.
