We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a2ae864 commit cf3d5cdCopy full SHA for cf3d5cd
Sprint-3/2-practice-tdd/count.js
@@ -1,11 +1,15 @@
1
function countChar(stringOfCharacters, findCharacter) {
2
let char = 0;
3
- for(let i = 0;i < stringOfCharacters.length;i++){
4
- if(stringOfCharacters[i] === findCharacter){
+ for(let i = 0;i <= stringOfCharacters.length - findCharacter.length;i++){
+ if ( findCharacter.length === 0 || stringOfCharacters === 0){
5
+ return 0;
6
+ }
7
+ if(stringOfCharacters.substring(i, i + findCharacter.length ) === findCharacter){
8
char++;
9
}
10
11
return char
12
13
14
module.exports = countChar;
15
+console.log(countChar("aaaaa","a"));
0 commit comments