diff --git a/kata/8-kyu/index.md b/kata/8-kyu/index.md index e54daf6e..70e09e59 100644 --- a/kata/8-kyu/index.md +++ b/kata/8-kyu/index.md @@ -128,6 +128,7 @@ - [Is it even?](is-it-even "555a67db74814aa4ee0001b5") - [Is n divisible by x and y?](is-n-divisible-by-x-and-y "5545f109004975ea66000086") - [Is the string uppercase?](is-the-string-uppercase "56cd44e1aa4ac7879200010b") +- [Is there a vowel in there?](is-there-a-vowel-in-there "57cff961eca260b71900008f") - [Is your period late?](is-your-period-late "578a8a01e9fd1549e50001f1") - [Jenny's secret message](jennys-secret-message "55225023e1be1ec8bc000390") - [Kata Example Twist](kata-example-twist "525c1a07bb6dda6944000031") diff --git a/kata/8-kyu/is-there-a-vowel-in-there/README.md b/kata/8-kyu/is-there-a-vowel-in-there/README.md new file mode 100644 index 00000000..22f977e8 --- /dev/null +++ b/kata/8-kyu/is-there-a-vowel-in-there/README.md @@ -0,0 +1,8 @@ +# [Is there a vowel in there?](https://www.codewars.com/kata/is-there-a-vowel-in-there "https://www.codewars.com/kata/57cff961eca260b71900008f") + +Given an array of numbers, check if any of the numbers are the character codes for lower case vowels (`a, e, i, o, u`). + +If they are, change the array value to a string of that vowel. + +`input [100,100,116,105,117,121]=>[100,100,116,"i","u",121] output` +Return the resulting array. \ No newline at end of file diff --git a/kata/8-kyu/is-there-a-vowel-in-there/main/VowelMapper.java b/kata/8-kyu/is-there-a-vowel-in-there/main/VowelMapper.java new file mode 100644 index 00000000..c629b0c5 --- /dev/null +++ b/kata/8-kyu/is-there-a-vowel-in-there/main/VowelMapper.java @@ -0,0 +1,7 @@ +import java.util.List; + +interface VowelMapper { + static List isVow(List a) { + return a.stream().map(i -> (Object) ("aeiou".indexOf(i) < 0 ? i : ((char) i.intValue()) + "")).toList(); + } +} \ No newline at end of file diff --git a/kata/8-kyu/is-there-a-vowel-in-there/test/VowelMapperTest.java b/kata/8-kyu/is-there-a-vowel-in-there/test/VowelMapperTest.java new file mode 100644 index 00000000..c9b5d6ba --- /dev/null +++ b/kata/8-kyu/is-there-a-vowel-in-there/test/VowelMapperTest.java @@ -0,0 +1,28 @@ +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.List; +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; + +class VowelMapperTest { + private static Stream testData() { + return Stream.of( + Arguments.of( + List.of(118, 117, 120, 121, 117, 98, 122, 97, 120, 106, 104, 116, 113, 114, 113, 120, 106), + List.of(118, "u", 120, 121, "u", 98, 122, "a", 120, 106, 104, 116, 113, 114, 113, 120, 106) + ), + Arguments.of( + List.of(101, 121, 110, 113, 113, 103, 121, 121, 101, 107, 103), + List.of("e", 121, 110, 113, 113, 103, 121, 121, "e", 107, 103) + ) + ); + } + + @ParameterizedTest + @MethodSource("testData") + void sample(List input, List expected) { + assertEquals(expected, VowelMapper.isVow(input)); + } +} \ No newline at end of file