-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomparePrimitives.js
33 lines (33 loc) · 1014 Bytes
/
comparePrimitives.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*!
* @author electricessence / https://github.com/electricessence/
* Licensing: MIT
*/
import areEqual from './areEqual';
/**
* Compares two comparable objects or primitives.
* @param a
* @param b
*/
function comparePrimitives(a, b) {
if (areEqual(a, b))
return 0 /* CompareResult.Equal */;
// Allow for special inequality..
if (a > b || a === 0 && b == 0 || a === null && b === undefined)
return 1 /* CompareResult.Greater */;
if (b > a || b === 0 && a == 0 || b === null && a === undefined)
return -1 /* CompareResult.Less */;
return NaN;
}
(function (comparePrimitives) {
/**
* Compares two comparable objects or primitives and inverts the sign of the result.
* @param a
* @param b
*/
function inverted(a, b) {
return -comparePrimitives(a, b);
}
comparePrimitives.inverted = inverted;
})(comparePrimitives || (comparePrimitives = {}));
export default comparePrimitives;
//# sourceMappingURL=comparePrimitives.js.map