Skip to content

Commit ab6e0d0

Browse files
committed
excercise 7
1 parent 31b1e84 commit ab6e0d0

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/functions-and-arrays.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,14 @@ const wordsCount = [
155155
];
156156

157157
function howManyTimes(arrayToSearchIn, wordToSearch) {
158-
158+
if (arrayToSearchIn.length === 0)
159+
return (0);
160+
let timesFound = 0;
161+
arrayToSearchIn.forEach(element => {
162+
if (element === wordToSearch)
163+
timesFound++;
164+
});
165+
return (timesFound);
159166
}
160167

161168

0 commit comments

Comments
 (0)