Skip to content

Commit d390b1e

Browse files
* docs: kata description * feat: kata/find-the-vowels --------- Co-authored-by: ParanoidUser <5120290+ParanoidUser@users.noreply.github.com>
1 parent 3893d16 commit d390b1e

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# [Find the vowels](https://www.codewars.com/kata/find-the-vowels "https://www.codewars.com/kata/5680781b6b7c2be860000036")
2+
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).
5+
6+
So given a string "super", we should return a list of `[2, 4]`.
7+
8+
Some examples:
9+
Mmmm => []
10+
Super => [2,4]
11+
Apple => [1,5]
12+
YoMama -> [1,2,4,6]
13+
14+
### NOTES
15+
16+
* Vowels in this context refers to: a e i o u y (including upper case)
17+
* This is indexed from `[1..n]` (not zero indexed!)
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[] vowelIndices(String word) {
5+
return range(0, word.length()).filter(i -> "aeiou".indexOf(word.charAt(i)) >= 0).map(i -> i + 1).toArray();
6+
}
7+
}
Lines changed: 25 additions & 0 deletions
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+
}

kata/7-kyu/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@
194194
- [Find the Squares](find-the-squares "60908bc1d5811f0025474291")
195195
- [Find the stray number](find-the-stray-number "57f609022f4d534f05000024")
196196
- [Find the sum of the roots of a quadratic equation](find-the-sum-of-the-roots-of-a-quadratic-equation "57d448c6ba30875437000138")
197+
- [Find the vowels](find-the-vowels "5680781b6b7c2be860000036")
197198
- [Find your caterer](find-your-caterer "6402205dca1e64004b22b8de")
198199
- [Finding queens on the board](finding-queens-on-the-board "64060d8ab2dd990058b7f8ee")
199200
- [Finding Remainder Without Using '%' Operator](finding-remainder-without-using-percent-operator "564f458b4d75e24fc9000041")

0 commit comments

Comments
 (0)