Consider the following scenario, where I have to sort a list of students by both name and scores.
[
{
name: 'Max',
score: 94
},
{
name: 'Jerome',
score: 86
},
{
name: 'Susan',
score: 86
},
{
name: 'Abel',
score: 86
},
{
name: 'Kevin',
score: 86
}
]
I want to sort the list by the student who scored the highest, but if two or more students have the same score, then I want to sort those students alphabetically. For the above case, the result should be as below:
[
{
name: 'Max',
score: 94
},
{
name: 'Abel',
score: 86
},
{
name: 'Jerome',
score: 86
},
{
name: 'Kevin',
score: 86
},
{
name: 'Susan',
score: 86
}
]
How can I achieve this? Is there any lodash function that I can use, or is it possible with pure JavaScript?