forked from alpana-d/FLW1_CodingChallenge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
minMax.js
55 lines (35 loc) · 1.14 KB
/
minMax.js
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
44
45
46
47
48
49
50
51
52
53
54
55
/*
~ DO IT SOLO ~
Min & Max in an Array
Implement a function that takes an array 'numbers' and prints out the largest and smallest numbers in that array
Sample outputs
#1
Input:
numbers = [10, 20, 30, 40, 50]
Output:
minValue = 10
maxValue = 50
#2
Input:
Numbers = [50, 30, 70, 100, 20, 40]
Output:
minValue = 20
maxValue = 100
#3
Input:
Numbers = [0, 0, 0, 0, 0]
Output:
minValue = 0
maxValue = 0
HINT #1: You can assume that the first number in the array is the minimum/maximum number and update it as you iterate through the array
HINT #2: Since the length of the 'numbers' array is unknown, you can find the length of the array using `numbers.length`
*/
let numbers = [10, 20, 30, 40, 50];
findMinAndMax(numbers);
function findMinAndMax(numbers) {
//1. Create variables minValue and maxValue to store the minimum and maximum numbers in the array. What should be the starting value of these variables?
//2. Create a for loop to iterate through the numbers array
//3. Update the values of the minimum and maximum numbers if needed
//4. Print out the number in the console
}
//5. Test your code using other arrays!