Complete the function/method so that it returns the url with anything after the anchor (#) removed.
Examples
remove_url_anchor('dev.to#about')
returns 'dev.to'
remove_url_anchor('www.telegraph.co.uk/branding')
returns 'www.telegraph.co.uk/branding'
Tests
remove_url_anchor('www.twitter.com?page=1')
remove_url_anchor('www.twitter.com#about')
Good luck!
This challenge comes from jhoffner on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge idea for a future post? Email yo+challenge@dev.to with your suggestions!
Top comments (13)
Haskell:
So much beautiful to read.
Here is the simple solution with
parse_url
function in PHP:Java:
REGEX to the rescue.
C# solution
JavaScript
Second parameter to
split
means it will stop looking after the first match, and never construct a second string value.Rust
look at it go!
Disclaimer:
In real life, please use developer.mozilla.org/docs/Web/API... or docs.rs/url/ respectively.
These should be fairly bulletproof though, since URL specification doesn't allow unencoded
#
character anywhere, including notably the<password>
section of<protocol>://<user>:<password>@<host>
. But where there's fragment, soon will come other parts of the URL.js using split method
JS
Python:
SQL (postgres)