Ad
  • Default User Avatar

    I assume he meant to extract the SLD, but I agree this should be clarified in the description.
    Furthermore I have to say, that testcases would be nice and you should also include the original URLs in the optional message.

    test.assert_equals(domain_name("http://example.com"), "example", "Testing http://example.com")

  • Custom User Avatar

    The task is misleading and the tests are flawed in many ways. The domain name for http://google.com is google.com not google. In that example, google is the SLD and com is the TLD, see wikipedia for reference. The description should specify what are we looking for in a way that it doesn't provide a bad example (calling the SLD the domain name).
    Due to this it also fails to categorise things such as example.co.uk. From the description I'd assume in this case we are looking to return example, however that would be quite hard to tell as in truth the SLD here is co.

    The tests don't cover many cases, for example (ignoring my note above about the invalidity of the task itself):

    test.assert_equals(domain_name(""), "")
    test.assert_equals(domain_name("https://youtube.com?r=http://google.com"), "youtube")
    test.assert_equals(domain_name("sub.domain.example.com"), "example")
    test.assert_equals(domain_name("https://foobar.co.uk"), "foobar")  # I'd personally expect 'co' to be returned here
    test.assert_equals(domain_name("https://facebook.com?"), "facebook")
    test.assert_equals(domain_name("https://www2.youtube.com"), "youtube")
    test.assert_equals(domain_name("https://com.com.com"), "com")
    test.assert_equals(domain_name("https://shopping.online"), "shopping")
    test.assert_equals(domain_name("www.something.net/index.com"), "something")
    test.assert_equals(domain_name("www.!nval!&.net"), "") # return "" if the url is invalid?