Question Bank

JavaScript Group Students by ID: Two Approaches Quiz

Difficulty: Medium

Two seeded approaches to group an array of student records by id (reduce + dict and the `in` operator), plus two companions on Map and Object.groupBy.

Question Bank
/

JavaScript Group Students by ID: Two Approaches Quiz

JavaScript Group Students by ID: Two Approaches Quiz

Two seeded approaches to group an array of student records by id (reduce + dict and the `in` operator), plus two companions on Map and Object.groupBy.

Question Bank
Medium
JavaScript
4 questions
quiz
arrays
hash-map
array-manipulation-patterns

419 views

8

Group an array of { id, score } records by id using reduce and an in-operator branch on the accumulator.

Examples

Example 1:

Input: [{id:1, score:11},{id:2, score:64},{id:1, score:87}]
Output: { 1: [11, 87], 2: [64] }
Explanation: Keys are student ids; values are the scores collected in iteration order.