Ad
  • Custom User Avatar

    In my understanding, this kata doesn't put any restriction on the input strings. So, 'abc' and 'c' are both valid strings. And what I want to comment is the RegEx solution can't cover special cases.

    Edit: Oh, now I understand that this RegEx solution is for the old version of this kata, and it was correct. Now the kata has changed, and it's no longer accurate. Anyway, I think we can update the test cases, but the kata's original description should not be changed. Otherwise, the solutions won't be consistent.

  • Custom User Avatar

    Correct, it'll fail.
    The author should have added that to the list of test-cases earlier (perhaps to intentionally escape weird inputs).
    It's not hard to either use endsWith (if available) or implement a trivial linear (O(n)) solution that scans each character from the end of the string.
    The latter could be then optimized by splitting the ending into two halves and checking first and last characters for each half (that way it'll give negative response faster than a linear solution).
    Just for your information, 'abc' and 'c' are both incorrect string literals since they should end with an additional apostrophe.

  • Custom User Avatar

    This solution is not correct for special cases such as:

    solution('ab(c)', '(c)');

    solution('abc\', 'c\');

    solution('abc+', 'c+');

  • Custom User Avatar

    The regex flag, 'i', might not be needed.
    But the question doesnt explicitly say that it needs case sensitive comparison, although the tests pass without the flag, 'i'.

  • Custom User Avatar

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

  • Custom User Avatar

    @ca6age:

    var handled = ending.replace(/[.+]/g, '\$&');
    return new RegExp(handled + "$", "i").test(str);

  • Default User Avatar

    Regex was my initial thought but I didn't know how it will handle string with regex symbols like '.', '+', etc.
    Any clues about that?

  • Custom User Avatar

    Could anyone explain to this newb, how does this work ?

  • Default User Avatar

    给跪。。。

  • Default User Avatar