This repository was archived by the owner on Feb 20, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +28
-1
lines changed Expand file tree Collapse file tree 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'
3838import isFunction from './is-function'
3939import isOdd from './is-odd'
4040import isNumeric from './is-numeric'
41+ import max from './max'
4142
4243export {
4344 isOdd ,
@@ -80,5 +81,5 @@ export {
8081 isFunction ,
8182 subtraction ,
8283 isNumeric ,
84+ max ,
8385}
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