Skip to content

Commit 5ec8d73

Browse files
committed
Iteration ironhack-labs#4: Calculate the average. Level 2:
1 parent 58bfe64 commit 5ec8d73

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/functions-and-arrays.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,24 @@ function averageNumbers(numbersAvg) {
6868
// Level 2: Array of strings
6969
const wordsArr = ['seat', 'correspond', 'linen', 'motif', 'hole', 'smell', 'smart', 'chaos', 'fuel', 'palace'];
7070

71-
function averageWordLength(wordsArr) {
71+
function averageWordLength(wordsArr) {
7272
if (wordsArr.length === 0) return null;
7373
if (wordsArr.length === 1) return wordsArr[0];
7474

75-
76-
75+
let sumWords = 0
76+
//for (let i = 0; i < wordsArr.length; i++) {
77+
//sumWords =+ wordsArr[i].length;
78+
//}
79+
//return sumWords / wordsArr.length;
80+
//}
81+
wordsArr.forEach(function (w) {
82+
sumWords += w.length;
83+
});
84+
return sumWords / wordsArr.length
7785
}
7886

79-
// Bonus - Iteration #4.1
87+
88+
// Bonus - Iteration #4.1
8089
function avg() {}
8190

8291
// Iteration #5: Unique arrays

0 commit comments

Comments
 (0)