Ad
  • Custom User Avatar

    I can appreciate what it was going for, but this kata is not a great problem-solving exercise because the requirements are not specific enough.

    It should be specified that the test cases will only ever have zero or one subdomains, and if it has one, it will always be "www." In the real world, URLs might include multiple subdomains (that could be anything) and a multi-part top-level domain (e.g. "host.sub1.sub2.domain.co.jp") so the premise is already too vague.

    A better exercise would be one that requires you to check an input URL against a predefined set of formatting rules (e.g. there will only be one subdomain, it may or may not have "http(s)", there will be no invalid characters, etc.), and return the domain name if it conforms to those rules, or an error/null if it does not.

  • Custom User Avatar

    I'm not claiming to have "found something new," I'm just trying to help people understand the description. There are many comments from people who are confused by the wording.

  • Custom User Avatar

    Description is extremely confusing so I've rewritten it, hope this helps people in the future:

    You are given a number "n" (n >= 0) and a digit "d" (0 <= d <= 9).
    
    Write a function nbDig(n, d) that finds the square of each integer from 0 to n, and returns the number of times that the digit d appears across all the squares. Note that d might appear multiple times in a single square.
    
    Example:
    
    n=12, d=1
    Squares from 0 to n=12: 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144
    The function returns 7 because the digit d=1 appears 7 times: in 1, 16, 81, 100, 121 (note: 1 appears twice in 121), and 144.
    
    n=10, d=0
    Squares from 0 to n=10: 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100
    The function returns 3 because the digit d=0 appears 3 times: in 0 and 100 (note: 0 appears twice in 100).