-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcount.js
More file actions
18 lines (15 loc) · 595 Bytes
/
Copy pathcount.js
File metadata and controls
18 lines (15 loc) · 595 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
function countChar(stringOfCharacters, findCharacter) {
// start a count of 0
let count = 0;
// check each of the characters in the string one by one.
for (let i = 0; i < stringOfCharacters.length; i++) {
// checks if the current characters matches the one were looking for in the string.
if (stringOfCharacters[i] === findCharacter)
// if it does, we increment the count by 1.
count = count + 1;
}
return count;
}
console.log(countChar("aaaaa", "a")); // 5
console.log(countChar("hello", "l")); // 2
module.exports = countChar;