Ad
  • Default User Avatar

    Hi,

    If you try to run an test of your own with the following values, what do you get as an answer?

    var values = [12, 11, 10, 9, 8];
    maximumSum(values, 3);
    
  • Default User Avatar

    The problematic parts would be here:

    var numbers = values
    ...
      maxArr.push(numbers.shift());
    

    Point being, assigning array (ie. values) to a new variable doesn't make even a shallow copy of the original array, i.e. any operations (in this case especially .shift() as it removes the element from the underlying array) made to the copy are reflected to the original. So, I'd suggest either making a "real" copy of the original array or using techniques that don't alter the original object. Hopefully this helps you enough :)

  • Default User Avatar

    Hi,

    From the instructions: "if n is larger than values.length, simply include values.length integers to the sum"

    i.e. these should return the same value:

    var values = [1, 2, 3];
    maximumSum(values, 3);
    maximumSum(values, 8);
    

    (Marking this issue as resolved, as I feel it isn't really an issue per se.)

  • Default User Avatar

    Yes, in case of all negative numbers, for example -5 to -1 as stated in your comment, the 2 maximum numbers are indeed -1 and -2. So, maximumSum would in that case be -3.

    However, the 2 minimum numbers are -5 and -4, and minimumSum is then -9. Hopefully this helps :)

  • Default User Avatar

    Hi Chris!

    Sorry it took me a while to answer - and actually sorry also for the bit misleading error message. Try this in your test suite, and see what happens:

    Test.assertEquals(minimumSum(new Array(5, 4, 3, 2, -11), 8), maximumSum(new Array(5, 4, 3, 2, -11), 8));
    

    The point you had missed is the last bullet point in the instructions:

    • if n is larger than values.length, simply include values.length integers to the sum

    But now that this came up, I think I'll edit the test suite a bit, to include a separate test for this.

  • Default User Avatar

    In the kata test cases, n is never negative (and how would you sum negative amount of integers?). The integers in the values array may, however, be negative (there is one such test case).

    I'll edit the kata description a bit, to make this more obvious.

  • Default User Avatar

    What do others think? I don't have a strict opinion either way.

  • Default User Avatar

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

  • Default User Avatar

    Good point - what was meant to happen is simply to include all values to both sums, I'll add something regarding that to the description.

    And thanks! My very first authored kata here, and not really based on any real-world problem, but thought something like this would be a simple and nice kata to work on :) And I wanted really bad to try authoring a kata ;)