Skip to content

Commit 14719e4

Browse files
committed
1 parent ba489ae commit 14719e4

File tree

3 files changed

+40
-7
lines changed

3 files changed

+40
-7
lines changed

kata/7-kyu/find-the-vowels/README.md

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
# [Find the vowels](https://www.codewars.com/kata/find-the-vowels "https://www.codewars.com/kata/5680781b6b7c2be860000036")
22

3-
We want to know the index of the vowels in a given word, for example, there are two vowels in the word super (the second and fourth letters).
3+
We want to know the index of the vowels in a given word, for example, there are two vowels in the word super (the second and fourth
4+
letters).
45

56
So given a string "super", we should return a list of `[2, 4]`.
67

7-
Some examples:
8-
Mmmm => []
9-
Super => [2,4]
10-
Apple => [1,5]
11-
YoMama -> [1,2,4,6]
8+
Some examples:
9+
Mmmm => []
10+
Super => [2,4]
11+
Apple => [1,5]
12+
YoMama -> [1,2,4,6]
1213

1314
### NOTES
1415

1516
* Vowels in this context refers to: a e i o u y (including upper case)
16-
* This is indexed from `[1..n]` (not zero indexed!)
17+
* This is indexed from `[1..n]` (not zero indexed!)
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[] vowelIndices(String word) {
5+
return range(0, word.length()).filter(i -> "aeiou".indexOf(word.charAt(i)) >= 0).map(i -> i + 1).toArray();
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import java.util.stream.Stream;
2+
import org.junit.jupiter.params.ParameterizedTest;
3+
import org.junit.jupiter.params.provider.Arguments;
4+
import org.junit.jupiter.params.provider.MethodSource;
5+
6+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
7+
import static org.junit.jupiter.params.provider.Arguments.arguments;
8+
9+
class VowelIndicesTest {
10+
private static Stream<Arguments> testData() {
11+
return Stream.of(
12+
arguments("mmm", new int[]{}),
13+
arguments("apple", new int[]{1, 5}),
14+
arguments("super", new int[]{2, 4}),
15+
arguments("orange", new int[]{1, 3, 6}),
16+
arguments("supercalifragilisticexpialidocious", new int[]{2, 4, 7, 9, 12, 14, 16, 19, 21, 24, 25, 27, 29, 31, 32, 33})
17+
);
18+
}
19+
20+
@ParameterizedTest
21+
@MethodSource("testData")
22+
void sample(String wd, int[] expected) {
23+
assertArrayEquals(expected, Kata.vowelIndices(wd));
24+
}
25+
}

0 commit comments

Comments
 (0)