Ad
  • Custom User Avatar
    1. The ways array contains different solutions for this Kata.
    2. The stringToNumber function executes all the functions in the array and then compares their results using the checkThemAll function.
    3. The checkThemAll function checks each next element. If at least one is incorrect, it will return NaN (and the tests will fail).

    Thus, we just execute all the functions in the ways array sequentially and check that they all give identical results.

    Frankly, these were my first steps in JavaScript. So I just got carried away experimenting with type conversions.
    And I'm not an alien, I'm a human :D

  • Custom User Avatar

    This solution doesn't work. It only checks two things:

    1. The string contains at least one character from RegExp.
    2. The number of matching characters is not less than the number of characters in RegExp.
    new RegExp(regexContainsAll('abcde')).test('aaaa'); // --> false
    new RegExp(regexContainsAll('abcde')).test('aaaaa'); // --> true
    

    But test cases do not contain such an elementary check. As always :)

  • Custom User Avatar

    I thought I was smart. But some people have found a way to solve this Kata in one line :D

  • Custom User Avatar

    Having solved this problem, I wanted to write that there is an inaccuracy in the description. But then I realized that this Kata imitates the real world. In the real world, you are distracted by stories about juniors, seniors, bosses, stackoverflow, etc. And no one says where the bug really is.

  • Custom User Avatar

    JavaScript test cases do not provide arrays like [1000, 0, 1, 0, 0, 0, 0] or [10, 0, 0, 0].
    Many existing solutions will break on such tests.

    As I can see, the same issue was already closed for Python 4 years ago.
    But for JS, the problem is still relevant.

  • Custom User Avatar

    But this is not how reduce works! Why are you all creating an initial value? If it is not given, then the first element of the array becomes the initial value.

  • Custom User Avatar

    Because the goal of your program is to determine that one of the players won.
    Otherwise, they will continue to play.

  • Custom User Avatar

    Because in real life, your program must determine by itself at what point one of the players won.
    Otherwise, players will continue to make moves.

    P.S. Sorry for my bad english. I hope I have explained it clearly.

  • Custom User Avatar

    It looks like there is a bug in the test cases.
    For input
    'abcdefghijklmnopqrstuvw xyz'
    the expected result is
    'abcdefghijklmnopqrstuvw -\nxyz'
    But it seems to me that the following result is more correct:
    'abcdefghijklmnopqrstuvw \nxyz' (with one or two spaces, but not with a hyphen)

  • Custom User Avatar

    It was a useful Kata. Now I know that localeCompare() does not work correctly with punctuation marks.

    console.log([":", ",", ".", ";"].sort());
    console.log([":", ",", ".", ";"].sort((a, b) => a.localeCompare(b)));
    
    // --> [",", ".", ":", ";"]
    // --> [",", ";", ":", "."]
    
  • Custom User Avatar
  • Custom User Avatar
    expected [ Array(21) ] to deeply equal [ Array(21) ]
    

    Please make the error messages more informative (JavaScipt).

    P.S. Okay, I found my mistake. And I liked this Kata :)
    Nevertheless, errors should be described in more detail.

  • Custom User Avatar

    Yes, it was a painful Kata that left mixed impressions. Not so bad actually =)

  • Custom User Avatar

    If you need a hint, maybe this will help.

    1. If count == null, it should be manually coerced to 32 (the default function parameter does not work for null).
    2. If you are converting an argument to a string, consider this:
       (-1).toString(2); //       --> "-1"
       (-1 >>> 0).toString(2); // --> "11111111111111111111111111111111"
    

    And this as well:

    (x | 0)   UInt32 --> Int32
    (x >>> 0) Int32 --> UInt32
    

    PS: Please don't mark this comment as a spoiler. It's just a hint for solving a poorly composed Kata.

  • Custom User Avatar

    JavaScript
    Hi! I see many people consider this Kata to be simple. =)
    If you really succeed in solving it, pleace explain to me this.

    Random tests:

    should equal ["ljrLG-224","F-522","BDCaKkTAz-863","GAjjzhgjl-1265","iZUiWx-2156","Bq-2853","f-3049",
                  "DYMxWfsJ-3487","Cdrtkfqe-3765","QI-4340","wnXFmPWK-5243","ijMQSFGc-5317","nJLVQPZcX-5418",
                  "FlCUN-5777","z-5995","HtlADdFQlX-6414","Oay-6565","TZQbgCbFM-7546","blFP-7862","LcCkKe-8307",
                  "FBvsHBz-8519","Oate-8846","lg-9419","wAMzSweA-34","OEdan-27"]
    

    Let's take only numbers:

    ["224", "522", "863", "1265", "2156", "2853", "3049", "3487", "3765", "4340", "5243", "5317",
     "5418", "5777", "5995", "6414", "6565", "7546", "7862", "8307", "8519", "8846", "9419", "34", "27"]
    

    It doesn't look like a sorted array. And I can't figure out how to find any pattern.
    Either the test cases are broken, or the problem needs to be better explained.

  • Loading more items...