array.sort_custom [method]
array.sort_custom( callable[, bool reverse ] )
sorts the array using the callable for comparisons, returns the array for chaining
This function is considerably slower than array.sort or array.sort_mapped so prefer those if performance matters.
- callable must return a number, specifying the relative order of the two passed arguments: less than 0 if first variable should be placed before second, greater than 0 if first variable should be placed after second, or 0 if it doesn't matter
- if
reverse
is true, array is sorted in the reverse order
a = [ 6, 8, 7, 5 ]; // this code will sort numbers into odd/even ones and in ascending order a.sort_custom( function(a,b){return a-b+(b%2-a%2)*1000; } ); // a = [5,7,6,8]