Always pass on a compare function to sort

This commit is contained in:
Bart van den Eijnden
2015-12-16 10:03:10 +01:00
parent dd4e88525e
commit e0be143ed5
11 changed files with 54 additions and 9 deletions

View File

@@ -37,6 +37,18 @@ ol.array.binaryFindNearest = function(arr, target) {
};
/**
* Default compare for array sort, will make sure number sort works okay.
* @param {*} a The first object to be compared.
* @param {*} b The second object to be compared.
* @return {number} A negative number, zero, or a positive number as the first
* argument is less than, equal to, or greater than the second.
*/
ol.array.defaultCompare = function(a, b) {
return a > b ? 1 : a < b ? -1 : 0;
};
/**
* Whether the array contains the given object.
* @param {Array.<*>} arr The array to test for the presence of the element.