Skip to content

Commit aa4774e

Browse files
* docs: kata description * feat: kata/help-bob-count-letters-and-digits --------- Co-authored-by: ParanoidUser <5120290+ParanoidUser@users.noreply.github.com>
1 parent 318c1e2 commit aa4774e

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# [Help Bob count letters and digits.](https://www.codewars.com/kata/help-bob-count-letters-and-digits "https://www.codewars.com/kata/5738f5ea9545204cec000155")
2+
3+
Bob is a lazy man.
4+
5+
He needs you to create a method that can determine how many ```letters``` (both uppercase and lowercase **ASCII** letters) and ```digits```
6+
are in a given string.
7+
8+
Example:
9+
10+
"hel2!lo" --> 6
11+
12+
"wicked .. !" --> 6
13+
14+
"!?..A" --> 1
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
interface Kata{
2+
static int countLettersAndDigits(String input){
3+
return input.replaceAll("[^a-zA-Z\\d]+", "").length();
4+
}
5+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
import static org.junit.jupiter.api.Assertions.assertEquals;
3+
4+
import org.junit.jupiter.params.ParameterizedTest;
5+
import org.junit.jupiter.params.provider.CsvSource;
6+
7+
class CountLettersAndDigitsTest {
8+
@ParameterizedTest
9+
@CsvSource(textBlock = """
10+
'', 0
11+
?, 0
12+
1, 1
13+
hel2!lo, 6
14+
n!!_ice!!123, 7
15+
aBcDeFg090, 10
16+
12345f%%%t5t&/6, 10
17+
u_n_d_e_r__S_C_O_R_E, 10
18+
""")
19+
void sample(String s, int expected) {
20+
assertEquals(expected, Kata.countLettersAndDigits(s));
21+
}
22+
}

kata/7-kyu/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@
236236
- [Harvest Festival](harvest-festival "606efc6a9409580033837dfb")
237237
- [Hëävÿ Mëtäl Ümläüts](heavy-metal-umlauts "57d4e99bec16701a67000033")
238238
- [Hello World - Without Strings](hello-world-without-strings "584c7b1e2cb5e1a727000047")
239+
- [Help Bob count letters and digits.](help-bob-count-letters-and-digits "5738f5ea9545204cec000155")
239240
- [Help Suzuki complete his chores!](help-suzuki-complete-his-chores "584dc1b7766c2bb158000226")
240241
- [Help Suzuki rake his garden!](help-suzuki-rake-his-garden "571c1e847beb0a8f8900153d")
241242
- [Help the Fruit Guy](help-the-fruit-guy "557af4c6169ac832300000ba")

0 commit comments

Comments
 (0)