mergeSort

external fun mergeSort(array: ReadonlyArray<Any>, comparator: mergeSortComparator, userDefinedObject: Any? = definedExternally)(source)

A stable merge sort.

// Assume array contains BoundingSpheres in world coordinates.
// Sort them in ascending order of distance from the camera.
const position = camera.positionWC;
mergeSort(array, function(a, b, position) {
return BoundingSphere.distanceSquaredTo(b, position) - BoundingSphere.distanceSquaredTo(a, position);
}, position);

Parameters

array

The array to sort.

comparator

The function to use to compare elements in the array.

userDefinedObject

Any item to pass as the third parameter to comparator.

See also