Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80742 views
1
/**
2
* The base implementation of `compareAscending` which compares values and
3
* sorts them in ascending order without guaranteeing a stable sort.
4
*
5
* @private
6
* @param {*} value The value to compare.
7
* @param {*} other The other value to compare.
8
* @returns {number} Returns the sort order indicator for `value`.
9
*/
10
function baseCompareAscending(value, other) {
11
if (value !== other) {
12
var valIsNull = value === null,
13
valIsUndef = value === undefined,
14
valIsReflexive = value === value;
15
16
var othIsNull = other === null,
17
othIsUndef = other === undefined,
18
othIsReflexive = other === other;
19
20
if ((value > other && !othIsNull) || !valIsReflexive ||
21
(valIsNull && !othIsUndef && othIsReflexive) ||
22
(valIsUndef && othIsReflexive)) {
23
return 1;
24
}
25
if ((value < other && !valIsNull) || !othIsReflexive ||
26
(othIsNull && !valIsUndef && valIsReflexive) ||
27
(othIsUndef && valIsReflexive)) {
28
return -1;
29
}
30
}
31
return 0;
32
}
33
34
module.exports = baseCompareAscending;
35
36