@@ -82,7 +82,7 @@ function averageNumbers(numbersAvg) {
82
82
sum += numbersAvg [ i ] ;
83
83
}
84
84
return sum / numbersAvg . length
85
- }
85
+ }
86
86
}
87
87
88
88
@@ -99,13 +99,13 @@ function averageWordLength(wordsArr) {
99
99
}
100
100
return sum / wordsArr . length
101
101
}
102
- }
102
+ }
103
103
104
104
// Bonus - Iteration #4.1
105
105
function avg ( mixedArr ) {
106
106
if ( mixedArr . length === 0 ) {
107
107
return null
108
- }
108
+ }
109
109
let allAvg = 0
110
110
for ( let i = 0 ; i < mixedArr . length ; ++ i ) {
111
111
if ( typeof mixedArr [ i ] === 'number' ) {
@@ -115,7 +115,7 @@ function avg(mixedArr) {
115
115
} else if ( typeof mixedArr [ i ] === 'boolean' ) {
116
116
+ mixedArr [ i ] ;
117
117
allAvg += mixedArr [ i ]
118
- }
118
+ }
119
119
}
120
120
return allAvg / mixedArr . length
121
121
}
@@ -152,27 +152,27 @@ function uniquifyArray() {
152
152
}
153
153
}
154
154
console . log ( wordsUnique )
155
- return wordsUnique
156
- }
155
+ return wordsUnique
156
+ }
157
157
158
158
159
159
160
160
// Iteration #6: Find elements
161
161
// const wordsFind = ['machine', 'subset', 'trouble', 'starting', 'matter', 'eating', 'truth', 'disobedience'];
162
162
163
- function doesWordExist ( wordsFind , word ) {
163
+ function doesWordExist ( wordsFind , word ) {
164
164
if ( wordsFind . length === 0 ) {
165
165
return null
166
166
} else if ( wordsFind . includes ( word ) === true ) {
167
- return true
167
+ return true
168
168
} else if ( wordsFind . includes ( word ) === false ) {
169
169
return false
170
170
}
171
171
}
172
172
173
173
174
174
// Iteration #7: Count repetition
175
- const wordsCount = [
175
+ /* const wordsCount = [
176
176
'machine',
177
177
'matter',
178
178
'subset',
@@ -184,9 +184,20 @@ const wordsCount = [
184
184
'truth',
185
185
'disobedience',
186
186
'matter'
187
- ] ;
187
+ ];*/
188
188
189
- function howManyTimes ( ) { }
189
+ function howManyTimes ( wordsCount , word ) {
190
+ if ( wordsCount . length === 0 ) {
191
+ return 0
192
+ }
193
+ let times = 0
194
+ for ( let i = 0 ; i < wordsCount . length ; ++ i ) {
195
+ if ( wordsCount [ i ] === word ) {
196
+ times += 1 ;
197
+ }
198
+ }
199
+ return times
200
+ }
190
201
191
202
192
203
0 commit comments