Skip to content

feat: kata/find-the-vowels #801

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions kata/7-kyu/find-the-vowels/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# [Find the vowels](https://www.codewars.com/kata/find-the-vowels "https://www.codewars.com/kata/5680781b6b7c2be860000036")

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).

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

Some examples:
Mmmm => []
Super => [2,4]
Apple => [1,5]
YoMama -> [1,2,4,6]

### NOTES

* Vowels in this context refers to: a e i o u y (including upper case)
* This is indexed from `[1..n]` (not zero indexed!)
7 changes: 7 additions & 0 deletions kata/7-kyu/find-the-vowels/main/Kata.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import static java.util.stream.IntStream.range;

interface Kata {
static int[] vowelIndices(String word) {
return range(0, word.length()).filter(i -> "aeiou".indexOf(word.charAt(i)) >= 0).map(i -> i + 1).toArray();
}
}
25 changes: 25 additions & 0 deletions kata/7-kyu/find-the-vowels/test/VowelIndicesTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import java.util.stream.Stream;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.params.provider.Arguments.arguments;

class VowelIndicesTest {
private static Stream<Arguments> testData() {
return Stream.of(
arguments("mmm", new int[]{}),
arguments("apple", new int[]{1, 5}),
arguments("super", new int[]{2, 4}),
arguments("orange", new int[]{1, 3, 6}),
arguments("supercalifragilisticexpialidocious", new int[]{2, 4, 7, 9, 12, 14, 16, 19, 21, 24, 25, 27, 29, 31, 32, 33})
);
}

@ParameterizedTest
@MethodSource("testData")
void sample(String wd, int[] expected) {
assertArrayEquals(expected, Kata.vowelIndices(wd));
}
}
1 change: 1 addition & 0 deletions kata/7-kyu/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@
- [Find the Squares](find-the-squares "60908bc1d5811f0025474291")
- [Find the stray number](find-the-stray-number "57f609022f4d534f05000024")
- [Find the sum of the roots of a quadratic equation](find-the-sum-of-the-roots-of-a-quadratic-equation "57d448c6ba30875437000138")
- [Find the vowels](find-the-vowels "5680781b6b7c2be860000036")
- [Find your caterer](find-your-caterer "6402205dca1e64004b22b8de")
- [Finding queens on the board](finding-queens-on-the-board "64060d8ab2dd990058b7f8ee")
- [Finding Remainder Without Using '%' Operator](finding-remainder-without-using-percent-operator "564f458b4d75e24fc9000041")
Expand Down
Loading