Skip to content

Commit 4258b15

Browse files
* docs: kata description * feat: kata/find-the-capitals-1 --------- Co-authored-by: ParanoidUser <5120290+ParanoidUser@users.noreply.github.com>
1 parent aa4774e commit 4258b15

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# [Find the capitals](https://www.codewars.com/kata/find-the-capitals-1 "https://www.codewars.com/kata/539ee3b6757843632d00026b")
2+
3+
Write a function that takes a single non-empty string of only lowercase and uppercase ascii letters (`word`) as its argument, and returns an
4+
ordered list containing the indices of all capital (uppercase) letters in the string.
5+
6+
# Example (Input --> Output)
7+
8+
```
9+
"CodEWaRs" --> [0,3,4,6]
10+
```
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import static java.util.stream.IntStream.range;
2+
3+
interface Kata {
4+
static int[] capitals(String s){
5+
return range(0, s.length()).filter(i -> s.charAt(i) < 91).toArray();
6+
}
7+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
2+
import static org.junit.jupiter.params.provider.Arguments.arguments;
3+
4+
import java.util.stream.Stream;
5+
import org.junit.jupiter.params.ParameterizedTest;
6+
import org.junit.jupiter.params.provider.Arguments;
7+
import org.junit.jupiter.params.provider.MethodSource;
8+
9+
class CapitalsTest {
10+
private static Stream<Arguments> testData() {
11+
return Stream.of(
12+
arguments("CodEWaRs", new int[]{0, 3, 4, 6}),
13+
arguments("aAbB", new int[]{1, 3}),
14+
arguments("AAA", new int[]{0, 1, 2}),
15+
arguments("abcdefghijklmnopqrstuvwxyz", new int[0]),
16+
arguments("ZYXWVUTSRQPONMLKJIHGFEDCBA", new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25}),
17+
arguments("", new int[0]));
18+
}
19+
20+
@ParameterizedTest
21+
@MethodSource("testData")
22+
void sample(String s, int[] expected) {
23+
assertArrayEquals(expected, Kata.capitals(s));
24+
}
25+
}

kata/7-kyu/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@
179179
- [Find min and max](find-min-and-max "57a1ae8c7cb1f31e4e000130")
180180
- [Find Screen Size](find-screen-size "5bbd279c8f8bbd5ee500000f")
181181
- [Find sum of top-left to bottom-right diagonals](find-sum-of-top-left-to-bottom-right-diagonals "5497a3c181dd7291ce000700")
182+
- [Find the capitals](find-the-capitals-1 "539ee3b6757843632d00026b")
182183
- [Find the index of the second occurrence of a letter in a string](find-the-index-of-the-second-occurrence-of-a-letter-in-a-string "63f96036b15a210058300ca9")
183184
- [Find the Missing Number](find-the-missing-number "57f5e7bd60d0a0cfd900032d")
184185
- [Find the next perfect square!](find-the-next-perfect-square "56269eb78ad2e4ced1000013")

0 commit comments

Comments
 (0)