Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Okay, I fixed the problem in the description, but it shouldn't change your solution
Yes, I understand the rules (or at least I think so). I do not understand how to create a program which uses
check_url
. I calledcheck_url
, assigned its result to valriableres
, and now what? How do I drive further logic depending on whether the ID is reported to be valid, or invalid? For example, how should I fill the gaps here:The point is, if the
check_url
returns a string on success and a string on failure, it is very difficult to tell whether the URL is valid or not. The choice of return values is very inconvenient.Normally there are double slashes in urls and alike:
I have now specified that the ID's have only the digits 0-9
A URL is valid if all of the following are true
1.The scheme (every charecter before the first
"/"
) has to equal"https:"
2.The Id (every charecter after the last
"/"
) has to have a length of five or fourIf the Id is four charecters long at this point you would add a
"0"
to the begining3.The modified Id does not start with "00"
The scheme is invalid if statement 1. is not true. The ID is invalid if either statement 2. or 3. are false.
Okay I have changed the
hs/UL.com/4
examples tohs:/UL.com/4
. And changed the use of protocol to schemeThis should be specified. This can also be surprising in context of working with URLs, because if
12%32
was a part of an URL, it would usually translate to three characters, not five.Let's assume that my program calls
res = check_url(some_url)
. What code should I write, what should I do withres
, to determine whether the URL is valid or not (and why not)?For this kata
12%32
has five, but all the IDs should only have the numerical digits 0-9 in themI am sorry for any confusion I have caused. If you are talking about outputs when either the ID or protocol is invalid
protocol_string = "{whatever the protocol is} is an invalid protocol."
Id_string = "{Id} is an invalid store ID."
.The returned string should have theprotocol_string
if the protocol is invalid and the Id isn't. If the ID is invalid but the protocol isn't you should returnId_string
. When both are invalid returnprotocol_string+Id_string
. If this is not what you're talking about, I do not quite understand what you are saying.URLs are tricky. Is
12%32
three characters, or five?Raising an appropriate, annotated,
Exception
on failure feels like the way to go here.Additionally, I think the better term would be "scheme". For example
mailto
andfile
are well known schemes commonly used in URLs, but they are not protocols.This should be actually an issue. Current design does not allow to easily distinguish success from invalid_scenario1 from invalid_scenario2.
Is there any way to distinguish result strings for valid and invalid inputs? Something like how Haskell has
Left "invalid ID"
andRight "12345"
?Searching return values for the substring
"invalid"
does not feel like good datatype design.Loading more items...