Ad
  • Default User Avatar

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

  • Default User Avatar

    me too. Did you ever figure it our?

  • Custom User Avatar

    Test.assertDeepEquals

  • Custom User Avatar

    Well, two ideas came to my mind.

    First. You just override Array.prototype.reduce and Array.prototype.concat to your function that will throw an error, you can't use this method or something simillar.

    Second, you still override it, but with an inner counter of invokes. You would assing these functions to a variables and on the prototype you would write your own function simillar to this.

      var originalReduce = Array.prototype.reduce, reduceCounter = 0;
      Array.prototype.reduce = function () {
        reduceCounter++;
        return originalReduce;
      }
    

    The test would check the counter if it has changed. In my mind this works, but you would have to check that for yourself ;).

  • Default User Avatar

    Please consider me a n00b specially in unit test but I really want this kata to get better.
    Can you tell me how to make a test whether or not reduce was used?
    Also I don't know if its possible to test if the solution has recursion. Thanks!

  • Default User Avatar

    You may wish to describe what 'flattening' an array means for those not familiar with the term, and provide a few examples. This does appear to be similar to another kata, btw.

  • Custom User Avatar

    If the arrays contain various data types and not just Numbers, then my "cheating" solution will fail.

  • Custom User Avatar

    You're not checking that reduce and concat are not used.

  • Default User Avatar

    I am new to unit testing, how can I use assert.deepEqual?

  • Default User Avatar

    The remainder should always have the same sign as the number you're dividing. a divided by b equals c with a remainder of d (a = b * c + d).

    Try running these tests:

    Test.assertEquals(remainder(5, 3), 2, "5 divided by 3 equals 1 with a remainder of 2 (5 = 3 * 1 + 2)");
    Test.assertEquals(remainder(5, -3), 2, "5 divided by -3 equals -1 with a remainder of 2 (5 = -3 * -1 + 2)");
    /* note: you can't run the next 2 tests since it always divides the larger number by the smaller. Otherwise, these would also work:
    Test.assertEquals(remainder(-5, 3), -2, "-5 divided by 3 equals -1 with a remainder of -2 (-5 = 3 * -1 + -2)");
    Test.assertEquals(remainder(-5, -3), -2, "-5 divided by -3 equals 1 with a remainder of -2 (-5 = -3 * 1 + -2)");
    */
    
  • Default User Avatar

    My code is passing all the test, but when I submit it, it says Should handle negative numbers - Expected: 40, instead got: -20
    Any tip in handling negative numbers?