Skip to content

Commit 62b0c77

Browse files
committed
Done the average of array of strings
1 parent 60b2996 commit 62b0c77

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/functions-and-arrays.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,18 @@ function averageNumbers(array) {
9191
// Level 2: Array of strings
9292
const wordsArr = ['seat', 'correspond', 'linen', 'motif', 'hole', 'smell', 'smart', 'chaos', 'fuel', 'palace'];
9393

94-
function averageWordLength() { }
94+
function averageWordLength(array) {
95+
if (array.length === 0 ){
96+
return null
97+
}
98+
let stringLength = 0
99+
for (let i = 0; i< array.length; i++) {
100+
stringLength += array[i].length
101+
}
102+
let average = stringLength / array.length
103+
return average
104+
}
105+
95106

96107
// Bonus - Iteration #4.1
97108
function avg() {}

0 commit comments

Comments
 (0)