@@ -10,13 +10,17 @@ function maxOfTwoNumbers(num1, num2){
10
10
11
11
// Iteration #2: Find longest word
12
12
const words = [ 'mystery' , 'brother' , 'aviator' , 'crocodile' , 'pearl' , 'orchard' , 'crackpot' ] ;
13
- function findLongestWord ( wordArray ) {
14
-
13
+ function findLongestWord ( arr ) {
14
+ let longestWord = "" ;
15
+ for ( let i = 0 ; i < arr . length ; i ++ ) {
16
+ if ( arr [ i ] . length > longestWord . length ) {
17
+ longestWord = arr [ i ]
18
+ }
19
+ }
20
+ return longestWord
15
21
}
16
22
17
23
18
-
19
-
20
24
// Iteration #3: Calculate the sum
21
25
const numbers = [ 6 , 12 , 1 , 18 , 13 , 16 , 2 , 1 , 8 , 10 ] ;
22
26
@@ -41,10 +45,17 @@ function sum() {}
41
45
// Level 1: Array of numbers
42
46
const numbersAvg = [ 2 , 6 , 9 , 10 , 7 , 4 , 1 , 9 ] ;
43
47
44
- function averageNumbers ( ) { }
48
+ function averageNumbers ( arr ) {
49
+ let avarege = 0
50
+ for ( let i = 0 ; i < arr . length ; i ++ ) {
51
+ avarege += arr [ i ] ;
52
+ }
53
+ return ( avarege / arr . length ) ;
54
+ }
55
+ console . log ( averageNumbers ( numbersAvg ) )
45
56
46
57
47
- // Level 2: Array of strings
58
+ // * Level 2: Array of strings
48
59
const wordsArr = [ 'seat' , 'correspond' , 'linen' , 'motif' , 'hole' , 'smell' , 'smart' , 'chaos' , 'fuel' , 'palace' ] ;
49
60
50
61
function averageWordLength ( ) { }
0 commit comments