Skip to content
This repository was archived by the owner on Feb 20, 2019. It is now read-only.

Commit 3c21883

Browse files
mis101birdKent C. Dodds
authored and
Kent C. Dodds
committed
feat(max): Add max function (#114) (#115)
the max function could find the maximum value of the list Closes #114
1 parent 5dfec97 commit 3c21883

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

src/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import checkPalindrome from './checkPalindrome'
3838
import isFunction from './is-function'
3939
import isOdd from './is-odd'
4040
import isNumeric from './is-numeric'
41+
import max from './max'
4142

4243
export {
4344
isOdd,
@@ -80,5 +81,5 @@ export {
8081
isFunction,
8182
subtraction,
8283
isNumeric,
84+
max,
8385
}
84-

src/max.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
}

test/max.test.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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+
})

0 commit comments

Comments
 (0)