Skip to content

Commit 8e7acf9

Browse files
committed
Iteration ironhack-labs#7
1 parent 790255e commit 8e7acf9

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/functions-and-arrays.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,8 @@ function doesWordExist(arrOfWords, searchWord) {
194194
{
195195
return true;
196196
}
197-
else
198-
{
199-
return false;
200-
}
201197
}
198+
return false;
202199
}
203200
doesWordExist(wordsFind, 'machine');
204201

@@ -218,9 +215,24 @@ const wordsCount = [
218215
'matter'
219216
];
220217

221-
function howManyTimes() {}
218+
function howManyTimes(arr, searchWord) {
222219

220+
if(arr.length === 0)
221+
{
222+
return null;
223+
}
223224

225+
let count = 0;
226+
for(let i = 0; i < arr.length; i++)
227+
{
228+
if(arr[i] === searchWord)
229+
{
230+
count++;
231+
}
232+
}
233+
return count;
234+
}
235+
howManyTimes(wordsCount, 'matter');
224236

225237
// Iteration #8: Bonus
226238
const matrix = [

0 commit comments

Comments
 (0)