Skip to content

Commit 790255e

Browse files
committed
ironhack-labs#6 where to add else statement
1 parent 91d2740 commit 790255e

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/functions-and-arrays.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,25 @@ uniquifyArray(wordsUnique);
182182
// Iteration #6: Find elements
183183
const wordsFind = ['machine', 'subset', 'trouble', 'starting', 'matter', 'eating', 'truth', 'disobedience'];
184184

185-
function doesWordExist(arr, searchfor) {
185+
function doesWordExist(arrOfWords, searchWord) {
186186

187+
if(arrOfWords.length === 0)
188+
{
189+
return null;
190+
}
191+
for(let i = 0; i < arrOfWords.length; i++)
192+
{
193+
if(arrOfWords[i] === searchWord)
194+
{
195+
return true;
196+
}
197+
else
198+
{
199+
return false;
200+
}
201+
}
187202
}
188-
doesWordExist(wordsFind, search);
203+
doesWordExist(wordsFind, 'machine');
189204

190205

191206
// Iteration #7: Count repetition

0 commit comments

Comments
 (0)