This repository was archived by the owner on Feb 20, 2019. It is now read-only.
File tree 3 files changed +28
-1
lines changed
3 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ import checkPalindrome from './checkPalindrome'
38
38
import isFunction from './is-function'
39
39
import isOdd from './is-odd'
40
40
import isNumeric from './is-numeric'
41
+ import max from './max'
41
42
42
43
export {
43
44
isOdd ,
@@ -80,5 +81,5 @@ export {
80
81
isFunction ,
81
82
subtraction ,
82
83
isNumeric ,
84
+ max ,
83
85
}
84
-
Original file line number Diff line number Diff line change
1
+ export default max
2
+ /**
3
+ * This method return the maximum value of the list that user gave
4
+ *
5
+ * @param {Array } list - get the maximum value of the list
6
+ * @returns {Number } - the maximum value of the list
7
+ */
8
+
9
+ function __getMax ( maxValue , value ) {
10
+ if ( value > maxValue ) {
11
+ maxValue = value
12
+ }
13
+ return maxValue
14
+ }
15
+
16
+ function max ( list ) {
17
+ return list . reduce ( __getMax , Number . NEGATIVE_INFINITY )
18
+ }
Original file line number Diff line number Diff line change
1
+ import test from 'ava'
2
+ import { max } from '../src'
3
+
4
+ test ( 'find the maximum value of list' , t => {
5
+ const list = [ 22 , 1 , 99 , 45 ]
6
+ const result = max ( list )
7
+ t . deepEqual ( 99 , result )
8
+ } )
You can’t perform that action at this time.
0 commit comments