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.
It's a little tip, but it helped me a lot!
Not an issue.
Oh hahahaha okay that's my problem then. I didn't know the tests were affected by me messing with the array. Thanks, that makes way more sense now because I was taking off two of the items. I didn't know why that would change the tests though, haha! Sorry for all the confusion.
Are you sorting the array? The sort method mutates the array in place (console.log doesn't, don't worry).
Your answer is right, and mutating the array has the side effect of the tests looking for wrong answer.
Oh wow that makes way more sense, thanks
That would make sense if I was removing items from the array, if the array came in as shown above shouldn't the answer be 46? My answer was 46, but it says it expected 96.
probably you use
pop
or somehting like that on the list further in your code. That's where you're mutating the input.Are you saying that I modified the original array by logging it at the beginning? Sorry just trying to understand if I'm doing something wrong. This problem is called "Sum of two lowest positive integers" wouldn't that mean the lowest two positive integers were 13 and 33? It just seemed like the answer was removing the two lowest, and then taking the next two lowest. This is how my function starts:
function sumTwoSmallestNumbers(numbers) {
console.log(numbers);
Hint: Do not modify the original array.
no, its suppose to be 63, its the largest consecutive sum. in this case, 63 was calculated from 2+43+-5+23
for yours (43+23), you would also need to include the -5, which results to: 43+-5+23
The problem would actually be quite interesting if there would be some constraints on the runtime (complexity)...
The answers on the test cases are wrong if I'm thinking this is supposed to work the way they said:
[ 17, -31, 3, 23, 5, 19, -27, -42, -25, -26, -21, 2, 43, -5, 23 ]
Expected: 63, instead got: 66
Shouldn't this answer be 66 because it would be 43 + 23?
Language: JavaScript
I had the same problem as you, I posted a question about it.
The tests are saying the wrong answer. I logged the array before I did anything, and the bottom two numbers in this array should have been 13 and 33 which would be 46. The test thought it should be 96.
should finally work for random tests
Log
[ 1072, 13, 33, 42, 54 ]
Expected: 96, instead got: 46