@@ -32,9 +32,10 @@ function findLongestWord(anArr) {
3232const numbers = [ 6 , 12 , 1 , 18 , 13 , 16 , 2 , 1 , 8 , 10 ] ;
3333
3434function sumNumbers ( anArr ) {
35+
3536 let total = 0
3637
37- for ( let i = 0 ; i < anArr . length ; i ++ ) {
38+ for ( let i = 0 ; i < anArr . length ; i ++ ) {
3839 total += anArr [ i ]
3940 }
4041 return total
@@ -44,18 +45,31 @@ function sumNumbers(anArr) {
4445function sum ( ) { }
4546
4647
47-
4848// Iteration #4: Calculate the average
4949// Level 1: Array of numbers
5050const numbersAvg = [ 2 , 6 , 9 , 10 , 7 , 4 , 1 , 9 ] ;
5151
52- function averageNumbers ( ) { }
53-
52+ function averageNumbers ( anArr ) {
53+ let average = 0 ;
54+
55+ let total = sumNumbers ( anArr )
56+
57+ average = total / anArr . length ;
58+ return average ;
59+ }
5460
5561// Level 2: Array of strings
5662const wordsArr = [ 'seat' , 'correspond' , 'linen' , 'motif' , 'hole' , 'smell' , 'smart' , 'chaos' , 'fuel' , 'palace' ] ;
5763
58- function averageWordLength ( ) { }
64+ function averageWordLength ( anArr ) {
65+ let total = 0 ;
66+
67+ for ( let i = 0 ; i < anArr . length ; i ++ ) {
68+ total += anArr [ i ] . length ;
69+ }
70+ let average = total / anArr . length ;
71+ return average
72+ }
5973
6074// Bonus - Iteration #4.1
6175function avg ( ) { }
0 commit comments