main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
1.0 KB
|
Line | |
---|
1 | var _curry2 =
|
---|
2 | /*#__PURE__*/
|
---|
3 | require("./internal/_curry2.js");
|
---|
4 |
|
---|
5 | var toString =
|
---|
6 | /*#__PURE__*/
|
---|
7 | require("./toString.js");
|
---|
8 | /**
|
---|
9 | * Returns the smaller of its two arguments.
|
---|
10 | *
|
---|
11 | * @func
|
---|
12 | * @memberOf R
|
---|
13 | * @since v0.1.0
|
---|
14 | * @category Relation
|
---|
15 | * @sig Ord a => a -> a -> a
|
---|
16 | * @param {*} a
|
---|
17 | * @param {*} b
|
---|
18 | * @return {*}
|
---|
19 | * @see R.minBy, R.max
|
---|
20 | * @example
|
---|
21 | *
|
---|
22 | * R.min(789, 123); //=> 123
|
---|
23 | * R.min('a', 'b'); //=> 'a'
|
---|
24 | */
|
---|
25 |
|
---|
26 |
|
---|
27 | var min =
|
---|
28 | /*#__PURE__*/
|
---|
29 | _curry2(function min(a, b) {
|
---|
30 | if (a === b) {
|
---|
31 | return a;
|
---|
32 | }
|
---|
33 |
|
---|
34 | function safeMin(x, y) {
|
---|
35 | if (x < y !== y < x) {
|
---|
36 | return y < x ? y : x;
|
---|
37 | }
|
---|
38 |
|
---|
39 | return undefined;
|
---|
40 | }
|
---|
41 |
|
---|
42 | var minByValue = safeMin(a, b);
|
---|
43 |
|
---|
44 | if (minByValue !== undefined) {
|
---|
45 | return minByValue;
|
---|
46 | }
|
---|
47 |
|
---|
48 | var minByType = safeMin(typeof a, typeof b);
|
---|
49 |
|
---|
50 | if (minByType !== undefined) {
|
---|
51 | return minByType === typeof a ? a : b;
|
---|
52 | }
|
---|
53 |
|
---|
54 | var stringA = toString(a);
|
---|
55 | var minByStringValue = safeMin(stringA, toString(b));
|
---|
56 |
|
---|
57 | if (minByStringValue !== undefined) {
|
---|
58 | return minByStringValue === stringA ? a : b;
|
---|
59 | }
|
---|
60 |
|
---|
61 | return a;
|
---|
62 | });
|
---|
63 |
|
---|
64 | module.exports = min; |
---|
Note:
See
TracBrowser
for help on using the repository browser.