-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray-max-min.js
More file actions
43 lines (34 loc) · 1 KB
/
array-max-min.js
File metadata and controls
43 lines (34 loc) · 1 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* 1. declare an arry
* 2. using function for find large number. pass the function parameters like "numbers"
* 3. declare a max variable for store maximum number while using for loop.
* 4. run for of loop.
* 5. in for of loop compare two value of array that store maximum (max) value.
* 6. out of for loop return max variable
* 7. out of the function, call the function and pass the parameter of an array's variable
*/
let heights = [60, 56, 74, 59, 62, 63, 65];
function getMax(numbers) {
let max = numbers[0];
for (const num of numbers) {
if (num > max) {
max = num;
}
}
return max;
}
let output = getMax(heights);
console.log("Max height is: ", output);
// Find the minimum value of an array.
let weight = [40, 45, 36, 58, 55, 47, 49, 43, 60];
function getMin(numbers){
let min = numbers[0];
for(const num of numbers ){
if(num < min){
min = num;
}
}
return min;
}
let result = getMin(weight);
console.log("minimum weight is: ", result);