I have a set of colours and the number of products found in that colour:
[
{colour: 'red', count: 100},
{colour: 'green', count: 30},
{colour: 'blue', count: 80},
...
]
The list is much longer than this. I want:
- to show the top ten colours with the highest count on top of the list,
- but sort that top 10 by alphabet.
I can only use a js compareFunction, once. Is there a way to achieve this?
Supplemental, I'm trying to get this sorting result in using the refinementList of the Algolia InstantSearch library. As documented, the sortBy can only take a single sorting function. If anyone has a different solution for that then that would of course also suffice.
I'm rather surprised by the eagerness of people to provide answers that don't fit the requirements. Regardless of the use case, this seems to me like an interesting problem to actually find a solution to.
this should provide some insight in how you can sort custom arrays. if you swap a and b around you'll sort into the opposite direction.
yes i'm aware you said you'd only want to use one compare function call but honestly.. if a prof is forcing you to do so, you might want to consider switching courses or make him realize his idiology is dumb for practical use.
after all, stackoverflow is not made to answer questions that have no relation to unefficient usecases.