Skip to content

Commit 9b176d2

Browse files
committed
refactored: removed .split on the string and iterated directly.
1 parent f641d30 commit 9b176d2

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

Sprint-3/2-practice-tdd/count.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
function countChar(stringOfCharacters, findCharacter) {
2-
if(stringOfCharacters === "" || findCharacter === ""){
3-
throw new Error("string an char are not given")
2+
if (stringOfCharacters === "" || findCharacter === "") {
3+
throw new Error("string an char are not given");
44
}
55

6-
const str = stringOfCharacters.split("")
76
let count = 0;
8-
for(const char of str){
9-
if(char === findCharacter){
10-
count++
7+
for (const char of stringOfCharacters) {
8+
if (char === findCharacter) {
9+
count++;
1110
}
1211
}
13-
return count
12+
return count;
1413
}
14+
console.log(countChar("aaaaaae", "a"));
1515
module.exports = countChar;

0 commit comments

Comments
 (0)