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.
So you can tell the program when you want to exit the function and get the value you're looking for.
Beginner here. Could someone explain why the return key word is being used here? Thanks.
JavaScript is pretty much designed to give you some salvageable output in as many cases as possible rather than exceptions or errors. Unless you do something really wrong (like calling a method that doesn't exist), you can usually assume something like
undefined
,null
orNaN
will be returned, and/or that the language will silently handle edge cases for you (like slicing an array past its end). This answer happens to be a case where both things are happening.This is just such a clean way of writing the test!
Also, may I ask: where in this code is anything turned into a string?
won't it leave an error when it turns the negative numbers to strings?
This comment is hidden because it contains spoiler information about the solution
This is a great answer if we're going for brevity, but if we broke out the reversal into a function and renamed 'rev' I think this would be a much more readable answer than dting's.