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.
I want dat bod! Voted clever for the -tail.length
This comment is hidden because it contains spoiler information about the solution
After reading some of the above posts, I added splice(0), but the tests are still failing. Now, every answer is still right, but now I'm getting "Expected: NaN, instead got..." What is the deal with these tests?
I also am seeing numbers interpretted in both directions in JavaScript in the final tests. The output prior to each test result, seems to me to be correct, and matches my answer, but doesn't match the expectation of the test.
Example:
Tests 0,0,1,1 ==> 3
Expected: 12, instead got: 3
I wish I knew what was going on here, cow b
Rather than adding
result
to the condition, you should have just didbreak
This is not a valid solution! It passes only by accident, because the tests are badly written.
Add this test and try again:
Test.expect(![3, -1, 0, 2].all(isGreaterThanZero), 'One is less than zero');
Hint, when you
return
in the middle of a loop, the loop stops, therefore only the first element is being checked.You will also iterate any object properties on the array if you iterate in this way. Also, v is global now.
Using filter or forEach, while more succinct, is less efficient for this sort of thing, since these functions will continue until the entire array has been iterated, whereas a normal loop (or functions like every/some) can be broken as soon as an element is found that does not meet the criteria.
This is unsafe array iteration. It works in this case, but in general it is bad practice. If the array has any non-numeric properties, this will iterate those as well.