Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Hi,
If you try to run an test of your own with the following values, what do you get as an answer?
The problematic parts would be here:
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 :)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:
(Marking this issue as resolved, as I feel it isn't really an issue per se.)
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 :)
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:
The point you had missed is the last bullet point in the instructions:
But now that this came up, I think I'll edit the test suite a bit, to include a separate test for this.
In the kata test cases,
n
is never negative (and how would you sum negative amount of integers?). The integers in thevalues
array may, however, be negative (there is one such test case).I'll edit the kata description a bit, to make this more obvious.
What do others think? I don't have a strict opinion either way.
This comment is hidden because it contains spoiler information about the solution
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 ;)