I've met a problem recently with "double" sorting.
Here is an array : array = ['201-4', '201-2', '200-1', '202-1']
I need to sort this array by the first number (200,201,202) AND by the second number (1,2,4). I succeeded by doing array.sort((a,b) => Number(a.split('-')[1]) - Number(b.split('-')[1])) // here I sort by the second number array.sort((a,b) => Number(a.split('-')[0]) - Number(b.split('-')[0])) // then here I sort by the first number
The issue is that I find that a bit dirty doing two sort for a single array since I'll be working with much longer array in the future and this may cause performance issue. I was wondering if there is a much cleaner way to deal with that ?
Thanks for your help !
I expect the array to be sorted from ['201-4', '201-2', '200-1', '202-1'] to ['200-1', '201-2', '201-4', '202-1']