Skip to content

Commit a733352

Browse files
committed
added function countChar
1 parent 89fcaf5 commit a733352

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

Sprint-3/revise/implement/card-validator.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function cardValidator(num) {
1010
// console.log(`compare ${numStr[i]} con ${firstDigit} in position ${i}`);
1111

1212
if (numStr[i] !== firstDigit) {
13-
// console.log(`diferent digit found: ${numStr[i]}`);
13+
// console.log(`different digit found: ${numStr[i]}`);
1414
return true; // Found at least two different digits
1515
}
1616
}
@@ -20,7 +20,7 @@ function cardValidator(num) {
2020
}
2121

2222
console.log(cardValidator(1111111111111111)); // Output: false and stop in the first return.
23-
// console.log(cardValidator(1234567890123456)); // Output: true
24-
// console.log(cardValidator(2222222222222222)); // Output: false
25-
// console.log(cardValidator(3333333333333334)); // Output: true
23+
console.log(cardValidator(1234567890123456)); // Output: true
24+
console.log(cardValidator(2222222222222222)); // Output: false
25+
console.log(cardValidator(3333333333333334)); // Output: true
2626

Sprint-3/revise/implement/count.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,17 @@
1515
// And a character char that does not exist within the case-sensitive str,
1616
// When the function is called with these inputs,
1717
// Then it should return 0, indicating that no occurrences of the char were found in the case-sensitive str.
18+
19+
20+
function countChar(str, char) {
21+
22+
let findSameLetter = 0;
23+
for(let i = 0; i < str.length; i++){
24+
if(str[i] === char){
25+
findSameLetter ++;
26+
}
27+
}
28+
return findSameLetter;
29+
}
30+
// 8
31+
console.log(countChar("Anibal", "a" ));

0 commit comments

Comments
 (0)