|
|
|
|
@ -24,7 +24,7 @@ numbers = [8,393,200,700,4,2000,638,29999, -2]
|
|
|
|
|
function findMaximum(){
|
|
|
|
|
|
|
|
|
|
if (!numbers.length){
|
|
|
|
|
|
|
|
|
|
null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let max = 0;
|
|
|
|
|
@ -40,7 +40,7 @@ return max;
|
|
|
|
|
function findMinimum(){
|
|
|
|
|
|
|
|
|
|
if (!numbers.length){
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
let min = numbers[0];
|
|
|
|
|
|
|
|
|
|
@ -55,7 +55,7 @@ return min;
|
|
|
|
|
function calculateSum(){
|
|
|
|
|
|
|
|
|
|
if (!numbers.length){
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let a = 0;
|
|
|
|
|
@ -82,7 +82,7 @@ function calculateSum(){
|
|
|
|
|
function SecondMaximum(){
|
|
|
|
|
|
|
|
|
|
if (!numbers.length){
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let max = numbers[0];
|
|
|
|
|
@ -97,8 +97,55 @@ let secondMax = 0;
|
|
|
|
|
return secondMax;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log(findMaximum());
|
|
|
|
|
console.log(SecondMaximum());
|
|
|
|
|
console.log(findMinimum());
|
|
|
|
|
console.log(calculateSum());
|
|
|
|
|
//console.log(findMaximum1())
|
|
|
|
|
//console.log(findMaximum());
|
|
|
|
|
//console.log(SecondMaximum());
|
|
|
|
|
//console.log(findMinimum());
|
|
|
|
|
//console.log(calculateSum());
|
|
|
|
|
//console.log(findMaximum1())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Exercise 3
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
### Exercise 3: String Array Processing
|
|
|
|
|
Create an array of your favorite movies/books/songs and practice different loop types.
|
|
|
|
|
|
|
|
|
|
**Requirements:**
|
|
|
|
|
- Create an array with at least 5 string values
|
|
|
|
|
- Use a traditional `for` loop to display items with numbers (1. Item Name)
|
|
|
|
|
- Use a `for...of` loop to display items in uppercase
|
|
|
|
|
- Use `forEach()` method to count and display the total characters
|
|
|
|
|
|
|
|
|
|
**Example Output:**
|
|
|
|
|
```
|
|
|
|
|
Traditional for loop:
|
|
|
|
|
1. The Matrix
|
|
|
|
|
2. Inception
|
|
|
|
|
3. Interstellar
|
|
|
|
|
|
|
|
|
|
For...of loop (uppercase):
|
|
|
|
|
THE MATRIX
|
|
|
|
|
INCEPTION
|
|
|
|
|
INTERSTELLAR
|
|
|
|
|
|
|
|
|
|
Character count:
|
|
|
|
|
Total characters across all titles: 42
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
const movies = ["Get Out", "Black Swan", "Godfather", "Obsession", "Lord of the Rings"]
|
|
|
|
|
|
|
|
|
|
function List(arr){
|
|
|
|
|
if (!arr.length){
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < arr.length; i++){
|
|
|
|
|
console.log(`${i}. ${arr[i]}`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|