Array Sorting and Grouping Challenges
Six sorting/grouping problems: dynamic key sort, multi-key sort, top-N average, date sort, top-N max preserving identity, group-by, and id-driven custom ordering.
Question Bank
Hard
JavaScript
quiz
arrays
sorting
hash-map
361 views
9
Implement dynamicSort(property) that returns a (a, b) comparator suitable for Array.prototype.sort, sorting ascending by property.
Examples
Example 1:
Input: people.sort(dynamicSort('age'))
Output: people sorted by ascending age
Explanation: Return -1 when `a[property] < b[property]`, 1 when greater, 0 when equal.5 more questions, with full solutions and explanations, are available for premium members.
Upgrade to Premium