source: node_modules/ramda/src/max.js

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
RevLine 
[d24f17c]1var _curry2 =
2/*#__PURE__*/
3require("./internal/_curry2.js");
4
5var toString =
6/*#__PURE__*/
7require("./toString.js");
8/**
9 * Returns the larger 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.maxBy, R.min
20 * @example
21 *
22 * R.max(789, 123); //=> 789
23 * R.max('a', 'b'); //=> 'b'
24 */
25
26
27var max =
28/*#__PURE__*/
29_curry2(function max(a, b) {
30 if (a === b) {
31 return b;
32 }
33
34 function safeMax(x, y) {
35 if (x > y !== y > x) {
36 return y > x ? y : x;
37 }
38
39 return undefined;
40 }
41
42 var maxByValue = safeMax(a, b);
43
44 if (maxByValue !== undefined) {
45 return maxByValue;
46 }
47
48 var maxByType = safeMax(typeof a, typeof b);
49
50 if (maxByType !== undefined) {
51 return maxByType === typeof a ? a : b;
52 }
53
54 var stringA = toString(a);
55 var maxByStringValue = safeMax(stringA, toString(b));
56
57 if (maxByStringValue !== undefined) {
58 return maxByStringValue === stringA ? a : b;
59 }
60
61 return b;
62});
63
64module.exports = max;
Note: See TracBrowser for help on using the repository browser.