File tree Expand file tree Collapse file tree 1 file changed +26
-4
lines changed Expand file tree Collapse file tree 1 file changed +26
-4
lines changed Original file line number Diff line number Diff line change @@ -177,8 +177,6 @@ function doesWordExist(arr, word) {
177
177
let i = 0 ;
178
178
let exists = false ;
179
179
while ( i < arr . length ) {
180
- console . log ( arr [ i ] ) ;
181
- console . log ( exists ) ;
182
180
if ( arr [ i ] === word ) {
183
181
exists = true ;
184
182
break ;
@@ -209,8 +207,32 @@ const wordsCount = [
209
207
'matter'
210
208
] ;
211
209
212
- function howManyTimes ( ) { }
213
-
210
+ function howManyTimes ( arr , word ) {
211
+ let i = 0 ;
212
+ let exists = false ;
213
+ let indices = [ ] ;
214
+
215
+ while ( i < arr . length ) {
216
+ let element = arr [ i ] ;
217
+ let idx = arr . indexOf ( element ) ;
218
+ if ( element === word ) {
219
+ while ( idx != - 1 ) {
220
+ indices . push ( idx ) ;
221
+ console . log ( indices ) ;
222
+ idx = arr . indexOf ( element , idx + 1 ) ;
223
+ }
224
+ exists = true ;
225
+ break ;
226
+ }
227
+ i ++ ;
228
+ }
229
+ if ( exists === false ) {
230
+ return 0 ;
231
+ } else {
232
+ return indices . length ;
233
+ }
234
+
235
+ }
214
236
215
237
216
238
// Iteration #8: Bonus
You can’t perform that action at this time.
0 commit comments