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
|
Rev | Line | |
---|
[d24f17c] | 1 | import _curry2 from "./internal/_curry2.js";
|
---|
| 2 | import toString from "./toString.js";
|
---|
| 3 | /**
|
---|
| 4 | * Returns the smaller of its two arguments.
|
---|
| 5 | *
|
---|
| 6 | * @func
|
---|
| 7 | * @memberOf R
|
---|
| 8 | * @since v0.1.0
|
---|
| 9 | * @category Relation
|
---|
| 10 | * @sig Ord a => a -> a -> a
|
---|
| 11 | * @param {*} a
|
---|
| 12 | * @param {*} b
|
---|
| 13 | * @return {*}
|
---|
| 14 | * @see R.minBy, R.max
|
---|
| 15 | * @example
|
---|
| 16 | *
|
---|
| 17 | * R.min(789, 123); //=> 123
|
---|
| 18 | * R.min('a', 'b'); //=> 'a'
|
---|
| 19 | */
|
---|
| 20 |
|
---|
| 21 | var min =
|
---|
| 22 | /*#__PURE__*/
|
---|
| 23 | _curry2(function min(a, b) {
|
---|
| 24 | if (a === b) {
|
---|
| 25 | return a;
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | function safeMin(x, y) {
|
---|
| 29 | if (x < y !== y < x) {
|
---|
| 30 | return y < x ? y : x;
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | return undefined;
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | var minByValue = safeMin(a, b);
|
---|
| 37 |
|
---|
| 38 | if (minByValue !== undefined) {
|
---|
| 39 | return minByValue;
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | var minByType = safeMin(typeof a, typeof b);
|
---|
| 43 |
|
---|
| 44 | if (minByType !== undefined) {
|
---|
| 45 | return minByType === typeof a ? a : b;
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | var stringA = toString(a);
|
---|
| 49 | var minByStringValue = safeMin(stringA, toString(b));
|
---|
| 50 |
|
---|
| 51 | if (minByStringValue !== undefined) {
|
---|
| 52 | return minByStringValue === stringA ? a : b;
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | return a;
|
---|
| 56 | });
|
---|
| 57 |
|
---|
| 58 | export default min; |
---|
Note:
See
TracBrowser
for help on using the repository browser.