Skip to content

Commit 8c1e686

Browse files
committed
add: until ironhack-labs#7
1 parent f3654aa commit 8c1e686

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

src/functions-and-arrays.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,6 @@ function doesWordExist(arr, word) {
177177
let i=0;
178178
let exists = false;
179179
while (i<arr.length) {
180-
console.log(arr[i]);
181-
console.log(exists);
182180
if (arr[i] === word) {
183181
exists = true;
184182
break;
@@ -209,8 +207,32 @@ const wordsCount = [
209207
'matter'
210208
];
211209

212-
function howManyTimes() {}
213-
210+
function howManyTimes(arr, word) {
211+
let i=0;
212+
let exists = false;
213+
let indices = [];
214+
215+
while (i<arr.length) {
216+
let element = arr[i];
217+
let idx = arr.indexOf(element);
218+
if (element === word) {
219+
while (idx != -1) {
220+
indices.push(idx);
221+
console.log(indices);
222+
idx = arr.indexOf(element, idx +1);
223+
}
224+
exists = true;
225+
break;
226+
}
227+
i++;
228+
}
229+
if (exists === false) {
230+
return 0;
231+
} else {
232+
return indices.length;
233+
}
234+
235+
}
214236

215237

216238
// Iteration #8: Bonus

0 commit comments

Comments
 (0)