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 larger 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.maxBy, R.min
|
---|
| 15 | * @example
|
---|
| 16 | *
|
---|
| 17 | * R.max(789, 123); //=> 789
|
---|
| 18 | * R.max('a', 'b'); //=> 'b'
|
---|
| 19 | */
|
---|
| 20 |
|
---|
| 21 | var max =
|
---|
| 22 | /*#__PURE__*/
|
---|
| 23 | _curry2(function max(a, b) {
|
---|
| 24 | if (a === b) {
|
---|
| 25 | return b;
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | function safeMax(x, y) {
|
---|
| 29 | if (x > y !== y > x) {
|
---|
| 30 | return y > x ? y : x;
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | return undefined;
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | var maxByValue = safeMax(a, b);
|
---|
| 37 |
|
---|
| 38 | if (maxByValue !== undefined) {
|
---|
| 39 | return maxByValue;
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | var maxByType = safeMax(typeof a, typeof b);
|
---|
| 43 |
|
---|
| 44 | if (maxByType !== undefined) {
|
---|
| 45 | return maxByType === typeof a ? a : b;
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | var stringA = toString(a);
|
---|
| 49 | var maxByStringValue = safeMax(stringA, toString(b));
|
---|
| 50 |
|
---|
| 51 | if (maxByStringValue !== undefined) {
|
---|
| 52 | return maxByStringValue === stringA ? a : b;
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | return b;
|
---|
| 56 | });
|
---|
| 57 |
|
---|
| 58 | export default max; |
---|
Note:
See
TracBrowser
for help on using the repository browser.