Tile - Array - Sort – Ylands

From Bohemia Interactive Community
Jump to navigation Jump to search

Sort(Array, Compare instruction)


sort(comparator: (objectA: T, objectB: T) => any): void;




Client, Server, Custom Controller


This instruction will sort the target array using a custom compare instruction.


  • When the instruction compares two values, it sends the values to the compare function, and sorts the values according to the returned (negative, zero, positive) value.

Example: When comparing 40 and 100, the instruction calls the compare function(40,100). The function calculates 40-100, and returns -60 (a negative value). The sort function will sort 40 as a value lower than 100.

  • Object A - Object B results in an ascending sorting order.
  • Object B - ** Object A** results in a descending sorting order.