Skip to content

Commit 05b8dcd

Browse files
committed
1 parent 8e16059 commit 05b8dcd

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/functions-and-arrays.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ if (numbers.length === 0) {
5050
}
5151

5252
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
5454
}
5555

5656
return sum
@@ -96,7 +96,7 @@ for (let i = 0 ; i < numbersAvg.length; i++) {
9696
}
9797

9898
console.log("hello")
99-
console.log(averageNumbers(255))
99+
console.log(averageNumbers(numbersAvg))
100100

101101

102102

@@ -207,30 +207,35 @@ console.log(uniquifyArray(wordsUnique));
207207

208208

209209

210+
// Iteration #6: Find elements
211+
const wordsFind = ['machine', 'subset', 'trouble', 'starting', 'matter', 'eating', 'truth', 'disobedience'];
212+
const wordToFind = 'starting'
210213

214+
function doesWordExist(wordsFind, wordToFind) {
215+
if (wordsFind.length === 0 ){
216+
return null // return null if empty
217+
}
211218

219+
for (let i=0; i<wordsFind.length; i++) {
220+
if (wordsFind[i]=== wordToFind){
221+
return true
222+
}
212223

224+
}
225+
return false
213226

214227

228+
}
215229

216230

217231

218232

233+
console.log(doesWordExist(wordsFind, wordToFind))
219234

220235

221236

222237

223238

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-
234239

235240

236241
// Iteration #7: Count repetition

0 commit comments

Comments
 (0)