-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(7-kyu): kata/from-a-to-z (#437)
- Loading branch information
1 parent
693afc4
commit 2abefd3
Showing
5 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# [From A to Z](https://www.codewars.com/kata/from-a-to-z "https://www.codewars.com/kata/6512b3775bf8500baea77663") | ||
|
||
Given a string indicating a range of letters, return a string which includes all the letters in that | ||
range, *including* the last letter. Note that if the range is given in *capital letters*, return the | ||
string in capitals also! | ||
|
||
### Examples | ||
|
||
``` | ||
"a-z" ➞ "abcdefghijklmnopqrstuvwxyz" | ||
"h-o" ➞ "hijklmno" | ||
"Q-Z" ➞ "QRSTUVWXYZ" | ||
"J-J" ➞ "J" | ||
``` | ||
|
||
### Notes | ||
|
||
- A *hyphen* will separate the two letters in the string. | ||
- You don't need to worry about error handling in this one (i.e. both letters will be the same case | ||
and the second letter will always be after the first alphabetically). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
interface Solution { | ||
static String gimmeTheLetters(String s) { | ||
var az = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ||
return az.substring(az.indexOf(s.charAt(0)), az.indexOf(s.charAt(2)) + 1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
|
||
class SolutionTest { | ||
@ParameterizedTest | ||
@CsvSource(textBlock = """ | ||
a-z, abcdefghijklmnopqrstuvwxyz | ||
h-o, hijklmno | ||
Q-Z, QRSTUVWXYZ | ||
J-J, J | ||
a-b, ab | ||
a-a, a | ||
g-i, ghi | ||
H-I, HI | ||
y-z, yz | ||
e-k, efghijk | ||
a-q, abcdefghijklmnopq | ||
F-O, FGHIJKLMNO | ||
""") | ||
void sample(String s, String ans) { | ||
assertEquals(ans, Solution.gimmeTheLetters(s)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters