mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
956 B
34 lines
956 B
10 years ago
|
/**
|
||
9 years ago
|
* Compares values to sort them in ascending order.
|
||
10 years ago
|
*
|
||
|
* @private
|
||
|
* @param {*} value The value to compare.
|
||
|
* @param {*} other The other value to compare.
|
||
|
* @returns {number} Returns the sort order indicator for `value`.
|
||
|
*/
|
||
9 years ago
|
function compareAscending(value, other) {
|
||
10 years ago
|
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;
|
||
|
}
|
||
|
|
||
9 years ago
|
module.exports = compareAscending;
|