There is such code:

export default class quickSort { constructor() {} private static partition(mas, l, r) { function swap(mas, a:any, b:any) { let tmp: any = mas[a]; mas[a] = mas[b]; mas[b] = tmp; return mas; } let pos = l-1; for (let i = l; i <= r; ++i) { if (mas[i] <= mas[r] ) mas = swap(mas, ++pos, i); } return pos; } private quick_sort(mas, l, r) { if (l >= r) { return; } let pivot = quickSort.partition(mas,l,r); this.quick_sort(mas,l,pivot-1); this.quick_sort(mas,pivot+1,r); } getSorted(mas, l, r) { this.quick_sort(mas,l,r); return mas; } } 

but it sorts a simple numeric array. It does not matter that it is a number, it is important that it is not nested. I want to write a method that will sort by a field in an array. Let id

  • why ... tell me why is the label fast and what should it mean? - Alexey Shimansky
  • @ Alexey Shimansky is a quick sort - Nikolay
  • Where? I do not see ..... even a quick sort here why? What does it complement, determine? Do not put useless tags if you do not know what they are and why they are needed - Alexey Shimansky
  • @ AlekseyShimansky yes, yes. Separate tags were written. Did not notice - Nikolay

1 answer 1

if (mas [i] <= mas [r])

change to

if (mas [i] .id <= mas [r] .id)

  • for each field a separate class to do? :-) - Grundy
  • @Grundy can and if (mas[i].["id"] <= mas[r].["id"] ) , so that all the rules - Nikolay
  • @Nikolay, in this form, the norms are not yet :-) The id is still tightly clogged :) - Grundy
  • @Grundy passing the desired string to the function. Or you can by the first field - Nikolay
  • @Nikolay, which of the four functions to transfer? - Grundy