Ad
  • Custom User Avatar

    Fixed. The author didn't care to fix it after a year it seems.

  • Custom User Avatar
  • Custom User Avatar
  • Custom User Avatar

    Fixed.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    God this is an ugly language

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    The code comment clearly says:

    ;Be sure to return longs. We don't want to return Clojure Ratios!

  • Custom User Avatar

    Probably tests are poorly written as you said. You can simply use a float for the dividend to get a decimal number instead of a ratio.

    (/ 5.0 2)
    => 2.5
    

    I propose the solution

    (float 5/2)
    => 2.5
    
  • Custom User Avatar

    Right, the test doesn't match the problem, which means this entire kata is really poorly written or I'm still missing something.

  • Custom User Avatar

    Looks like the tests don't cover that.

  • Custom User Avatar

    How is this correct? It returns Ratios.

    (find-average [1 2 3 4])
    5/2

  • Default User Avatar

    thanks for the reply this is new to me and i'm sure it will come in handy later

  • Custom User Avatar

    Regex is used to test (using Boolean values) and manipulate strings in many different programming languages such as JavaScript, Python, Java, C++ and more. Overall, the code looks through each item in the array and checks whether the username is validate. If all the usernames are valid, then return true, if not all of them are valid return false.

    1.)

    /^(?=.*\d+)(?=.*[a-z])[a-z\d]{6,10}$/g
    
    ^ asserts position at start of the string
    Positive Lookahead (?=.*\d+)
    Assert that the Regex below matches
    .* matches any character (except for line terminators)
    * Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
    \d+ matches a digit (equal to [0-9])
    + Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed (greedy)
    Positive Lookahead (?=.*[a-z])
    Assert that the Regex below matches
    .* matches any character (except for line terminators)
    * Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
    Match a single character present in the list below [a-z]
    a-z a single character in the range between a (ASCII 97) and z (ASCII 122) (case sensitive)
    Match a single character present in the list below [a-z\d]{6,10}
    {6,10} Quantifier — Matches between 6 and 10 times, as many times as possible, giving back as needed (greedy)
    a-z a single character in the range between a (ASCII 97) and z (ASCII 122) (case sensitive)
    \d matches a digit (equal to [0-9])
    $ asserts position at the end of the string, or before the line terminator right at the end of the string (if any)
    
    Global pattern flags
    g modifier: global. All matches (don't return after first match)
    

    from https://regex101.com/

    2.) "?=" is a special regex group called a "positive lookahead" which matches at a position where the pattern inside the lookahead can be matched (it matches the object before the lookahead).

    3.) .test(x) returns a Boolean value (true or false) based on the regular expression. It tests whether that specified regex appears in the string at all anywhere in the string. If it appears at least once then return true else false.