Skip to content

Commit 6fd8f80

Browse files
committed
add iteration ironhack-labs#4.1
1 parent beeb86b commit 6fd8f80

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/functions-and-arrays.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,16 @@ function averageWordLength(wordsArr) {
8585
}
8686
}
8787
// Bonus - Iteration #4.1
88-
function avg() {}
88+
function avg(mixedArr) {
89+
const isEmptyArr = mixedArr.length === 0;
90+
if (isEmptyArr) {
91+
return null;
92+
} else {
93+
const result = sum(mixedArr);
94+
//toFixed(2) shortens the result to 2 decimals after comma as String. Number() converts to number again
95+
return Number((result / mixedArr.length).toFixed(2));
96+
}
97+
}
8998

9099
// Iteration #5: Unique arrays
91100
const wordsUnique = [

0 commit comments

Comments
 (0)