mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 15:27:50 +00:00
40 lines
1.1 KiB
JavaScript
40 lines
1.1 KiB
JavaScript
define([], function() {
|
|
|
|
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
|
|
var undefined;
|
|
|
|
/**
|
|
* Compares values to sort them in ascending order.
|
|
*
|
|
* @private
|
|
* @param {*} value The value to compare.
|
|
* @param {*} other The other value to compare.
|
|
* @returns {number} Returns the sort order indicator for `value`.
|
|
*/
|
|
function compareAscending(value, other) {
|
|
if (value !== other) {
|
|
var valIsNull = value === null,
|
|
valIsUndef = value === undefined,
|
|
valIsReflexive = value === value;
|
|
|
|
var othIsNull = other === null,
|
|
othIsUndef = other === undefined,
|
|
othIsReflexive = other === other;
|
|
|
|
if ((value > other && !othIsNull) || !valIsReflexive ||
|
|
(valIsNull && !othIsUndef && othIsReflexive) ||
|
|
(valIsUndef && othIsReflexive)) {
|
|
return 1;
|
|
}
|
|
if ((value < other && !valIsNull) || !othIsReflexive ||
|
|
(othIsNull && !valIsUndef && valIsReflexive) ||
|
|
(othIsUndef && valIsReflexive)) {
|
|
return -1;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
return compareAscending;
|
|
});
|