mergeSort

mergeSort

A stable merge sort.

Parameters:
Name Type Argument Description
array Array The array to sort.
comparator Function The function to use to compare the item to elements in the array. If the first parameter is less than the second parameter, the function should return a negative value. If it is greater, the function should return a positive value. If the items are equal, it should return 0.
userDefinedObject Object <optional>
An object to pass as the third parameter to comparator.
Example
// Sort an array of numbers in increasing order
var array = // Array of bounding spheres in world coordinates
var position = camera.positionWC;
mergeSort(array, function(a, b, position) {
    return BoundingSphere.distanceSquaredTo(b.sphere, position) - BounsingSphere.distanceSquaredTo(a.sphere, position);
}, position);
Source: