Ad
  • Custom User Avatar

    Wrote a 3rd solution that includes a combine function and it improves readability when I compared with my 2nd solution.

    Cheers ;-)

  • Custom User Avatar

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

  • Custom User Avatar

    Unfortunately, I cannot edit the tests any more, as too many people have completed this kata.

    1. Test.randomize() is part of the test quite built-in to Codewars. It randomizes the order of the given array.
    2. That is true. And I am testing the function written by the coder. So that's why I make multiple tests when they should have the same result. If there's some edge case to the coder's solution, then they could fail on a seemingly straight-forward test case.
    3. Could you paste in the messages for those mentioned tests? The test messages should print out the input for each test.

    Infinity should be AN, I think. The idea is to make sure the value is a number of some kind, so Infinity should be allowed. As I said, I cannot add this in, but that's a good idea, nonetheless.

  • Custom User Avatar

    I find the test case difficult to read and understand. As a rule of thumb I try to make my tests as simple as possible in order to avoid false positive/negative.

    1. I can't see the value of randomize()
    2. If you assert that 2 is a number, there is no reason that 3 won't be a number. You're testing the function not the language.
    3. Same comment for "1", "2", "3" and new Number(1), new Number(2), ...

    Wouldn't the following tests achieve the same thing?

    Test.assertEquals(isAN(1)              , true , 'expected true for 1');
    Test.assertEquals(isAN(new Number(1))  , true , 'expected true for new Number(1)');
    Test.assertEquals(isAN('1')            , false, 'expected false for "1"');
    Test.assertEquals(isAN(new Number("a")), false, 'expected true for new Number("a")');
    //...
    

    Also I can't see a test for Infinity. I've seen solutions using window.isFinite() to exclude such number.

    Having said that what I thought would be quite straightforward turned out to be a bit trickier. So thanks for that!