Skip to content

Simon Björkberg WDPT-MAR23 #3698

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
last commit was iteration 6, now I added iteration 7
  • Loading branch information
SimonBjorkberg committed Mar 28, 2023
commit 80b52d6151b35169cdcaa3183fb3d0711d345436
19 changes: 17 additions & 2 deletions src/functions-and-arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,24 @@ const wordsCount = [
'matter'
];

function howManyTimes() {}

function howManyTimes(words, word) {
if (words.length === 0) {
return 0;
}
let sum = 0;
for (let i = 0; i < words.length; i++) {
if (words[i] !== word) {
continue;
}
else if (words[i] === word) {
sum += 1;
}
}
return sum;
}

let testing = howManyTimes(wordsCount, "matter")
console.log(testing)

// Iteration #8: Bonus
const matrix = [
Expand Down