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

    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!