-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlargest-lowest.js
More file actions
33 lines (29 loc) · 915 Bytes
/
largest-lowest.js
File metadata and controls
33 lines (29 loc) · 915 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
28
29
30
31
32
33
// 7(Largest & Lowest Number)
// function maxInArray(numbers){
// let largest = numbers[0];
// for(let i = 0; i < numbers.length; i++){
// const index = i;
// const element = numbers[index];
// if(element > largest){
// largest = element;
// }
// }
// return largest;
// }
// const heights = [167, 190, 120, 165, 137, 265];
// const tallest = maxInArray(heights);
// console.log('tallest person is: ', tallest);
// Homework: Write a function to get the lowest number in an array
function lowestInArray(numbers) {
let lowest = numbers[0];
for (let i = 0; i < numbers.length; i++) {
const element = numbers[i];
if (lowest > element) {
lowest = element;
}
}
return lowest;
}
const myNumbers = [167, 190, 120, 165, 137, 265];
const myLowestNumber = lowestInArray(myNumbers);
console.log(myLowestNumber);