Skip to content

Commit 5b0c9be

Browse files
committed
Done averafe of any type of array inside. Althoug it is a Bonus, I did it.
1 parent 62b0c77 commit 5b0c9be

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/functions-and-arrays.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,27 @@ function averageWordLength(array) {
105105

106106

107107
// Bonus - Iteration #4.1
108-
function avg() {}
108+
function avg(anytype) {
109+
if (anytype.length === 0){
110+
return null
111+
}
112+
let numbers = 0
113+
let sumStrings = 0
114+
let booleans = 0
115+
for (let i = 0 ; i < anytype.length; i++){
116+
if (typeof anytype[i] === 'number') {
117+
numbers += anytype[i]
118+
} else if (typeof anytype[i] === 'string'){
119+
sumStrings += anytype[i].length
120+
} else if (typeof anytype[i] === 'boolean') {
121+
booleans += anytype[i]
122+
} else {
123+
return error // No consigo pasar este punto me pide que arroje un error y es lo que hago...
124+
}
125+
}
126+
let average = (numbers + sumStrings + booleans)/ anytype.length
127+
return average;
128+
}
109129

110130
// Iteration #5: Unique arrays
111131
const wordsUnique = [

0 commit comments

Comments
 (0)