-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
min.js
41 lines (35 loc) · 984 Bytes
/
min.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
34
35
36
37
38
39
40
41
import _curry2 from './internal/_curry2.js';
import toString from './toString.js';
/**
* Returns the smaller of its two arguments.
*
* @func
* @memberOf R
* @since v0.1.0
* @category Relation
* @sig Ord a => a -> a -> a
* @param {*} a
* @param {*} b
* @return {*}
* @see R.minBy, R.max
* @example
*
* R.min(789, 123); //=> 123
* R.min('a', 'b'); //=> 'a'
*/
var min = _curry2(function min(a, b) {
if (a === b) { return a; }
function safeMin(x, y) {
if ((x < y) !== (y < x)) { return y < x ? y : x; }
return undefined;
}
var minByValue = safeMin(a, b);
if (minByValue !== undefined) { return minByValue; }
var minByType = safeMin(typeof a, typeof b);
if (minByType !== undefined) { return minByType === typeof a ? a : b; }
var stringA = toString(a);
var minByStringValue = safeMin(stringA, toString(b));
if (minByStringValue !== undefined) { return minByStringValue === stringA ? a : b; }
return a;
});
export default min;