-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFIndMaxandMin.js
More file actions
27 lines (22 loc) · 837 Bytes
/
FIndMaxandMin.js
File metadata and controls
27 lines (22 loc) · 837 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/* Instructions/Task:
Your task is to make two functions ( max and min, or maximum and minimum, etc., depending on the language ) that receive a list of integers as input, and return the largest and lowest number in that list, respectively.
Examples (Input -> Output)
* [4,6,2,1,9,63,-134,566] -> max = 566, min = -134
* [-52, 56, 30, 29, -54, 0, -110] -> min = -110, max = 56
* [42, 54, 65, 87, 0] -> min = 0, max = 87
* [5] -> min = 5, max = 5
Notes
You may consider that there will not be any empty arrays/vectors.
*/
//My answer
var min = function (list) {
return Math.min(...list);
// return list[0];
};
var max = function (list) {
return Math.max(...list);
// return list[0];
};
//Test cases ;
console.log(max([1, 2, 3, 4]));
console.log(min([1, 2, 3, 4]));