222. Group Heroes by Class
Easy · Hash Table
Given an array of hero objects with `name` and `heroClass`, group them by class and return an object where each key is a class name and the value is an array of hero names.
Examples
Example 1
Input: [{name:"Luna",heroClass:"Mage"},{name:"Max",heroClass:"Warrior"},{name:"Zara",heroClass:"Mage"}]
Output: {Mage:["Luna","Zara"],Warrior:["Max"]}
Explanation: Grouped by classConstraints
- 1 ≤ heroes.length ≤ 50