Higher Order Functions

Reduce Into an Object

Reduce Into an Object

reduce does not have to return a number. The accumulator can be an object that grows as each item contributes information.

Counting by a property is a practical example: the source array can contain statuses you did not know ahead of time, so the accumulator must create keys as it encounters them. A good implementation handles repeated statuses, new statuses, and an empty list.

Your task: Complete countTicketsByStatus so it returns an object where each key is a ticket status and each value is the number of tickets with that status.

Free with a JS Exercises account

Sign in to start coding, run your solution, and keep your progress saved for later. No payment needed.

By continuing, you agree to our Terms and Privacy Policy. We'll send occasional product updates and news. You can unsubscribe anytime.

Reduce Into an Object

reduce does not have to return a number. The accumulator can be an object that grows as each item contributes information.

Counting by a property is a practical example: the source array can contain statuses you did not know ahead of time, so the accumulator must create keys as it encounters them. A good implementation handles repeated statuses, new statuses, and an empty list.

Your task: Complete countTicketsByStatus so it returns an object where each key is a ticket status and each value is the number of tickets with that status.

Free with a JS Exercises account

Sign in to start coding, run your solution, and keep your progress saved for later. No payment needed.

By continuing, you agree to our Terms and Privacy Policy. We'll send occasional product updates and news. You can unsubscribe anytime.

Console

Run code to see output.