@@ -50,7 +50,7 @@ if (numbers.length === 0) {
50
50
}
51
51
52
52
for ( let i = 0 ; i < numbers . length ; i ++ ) { //should return the sum with one number array
53
- sum += numbers [ i ]
53
+ sum += numbers [ i ] // += "add and assign" , [i] is the loop counter, represents each element of the array as loop goes on
54
54
}
55
55
56
56
return sum
@@ -96,7 +96,7 @@ for (let i = 0 ; i < numbersAvg.length; i++) {
96
96
}
97
97
98
98
console . log ( "hello" )
99
- console . log ( averageNumbers ( 255 ) )
99
+ console . log ( averageNumbers ( numbersAvg ) )
100
100
101
101
102
102
@@ -207,30 +207,35 @@ console.log(uniquifyArray(wordsUnique));
207
207
208
208
209
209
210
+ // Iteration #6: Find elements
211
+ const wordsFind = [ 'machine' , 'subset' , 'trouble' , 'starting' , 'matter' , 'eating' , 'truth' , 'disobedience' ] ;
212
+ const wordToFind = 'starting'
210
213
214
+ function doesWordExist ( wordsFind , wordToFind ) {
215
+ if ( wordsFind . length === 0 ) {
216
+ return null // return null if empty
217
+ }
211
218
219
+ for ( let i = 0 ; i < wordsFind . length ; i ++ ) {
220
+ if ( wordsFind [ i ] === wordToFind ) {
221
+ return true
222
+ }
212
223
224
+ }
225
+ return false
213
226
214
227
228
+ }
215
229
216
230
217
231
218
232
233
+ console . log ( doesWordExist ( wordsFind , wordToFind ) )
219
234
220
235
221
236
222
237
223
238
224
-
225
-
226
-
227
-
228
-
229
- // Iteration #6: Find elements
230
- const wordsFind = [ 'machine' , 'subset' , 'trouble' , 'starting' , 'matter' , 'eating' , 'truth' , 'disobedience' ] ;
231
-
232
- function doesWordExist ( ) { }
233
-
234
239
235
240
236
241
// Iteration #7: Count repetition
0 commit comments