File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -105,7 +105,27 @@ function averageWordLength(array) {
105
105
106
106
107
107
// 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
+ }
109
129
110
130
// Iteration #5: Unique arrays
111
131
const wordsUnique = [
You can’t perform that action at this time.
0 commit comments