Skip to content
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
1 change: 1 addition & 0 deletions kata/7-kyu/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@
- [Regexp Basics - is it a six bit unsigned number?](regexp-basics-is-it-a-six-bit-unsigned-number "567e8dbb9b6f4da558000030")
- [Regexp Basics - is it a vowel?](regexp-basics-is-it-a-vowel "567bed99ee3451292c000025")
- [Regexp basics - parsing prices](regexp-basics-parsing-prices "56833b76371e86f8b6000015")
- [Remove anchor from URL](remove-anchor-from-url "51f2b4448cadf20ed0000386")
- [Remove consecutive duplicate words](remove-consecutive-duplicate-words "5b39e91ee7a2c103300018b3")
- [Remove duplicate words](remove-duplicate-words "5b39e3772ae7545f650000fc")
- [Remove the minimum](remove-the-minimum "563cf89eb4747c5fb100001b")
Expand Down
10 changes: 10 additions & 0 deletions kata/7-kyu/remove-anchor-from-url/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# [Remove anchor from URL](https://www.codewars.com/kata/remove-anchor-from-url "https://www.codewars.com/kata/51f2b4448cadf20ed0000386")

Complete the function/method so that it returns the url with anything after the anchor (`#`) removed.

## Examples

```
"www.codewars.com#about" --> "www.codewars.com"
"www.codewars.com?page=1" -->"www.codewars.com?page=1"
```
5 changes: 5 additions & 0 deletions kata/7-kyu/remove-anchor-from-url/main/Kata.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
interface Kata {
static String removeUrlAnchor(String url) {
return url.replaceAll("#.*", "");
}
}
17 changes: 17 additions & 0 deletions kata/7-kyu/remove-anchor-from-url/test/SolutionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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 = """
www.codewars.com#about, www.codewars.com
www.codewars.com/katas/?page=1#about, www.codewars.com/katas/?page=1
www.codewars.com/katas/, www.codewars.com/katas/
https://example.com#section1, https://example.com
""")
void sample(String url, String expected) {
assertEquals(expected, Kata.removeUrlAnchor(url));
}
}