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?
Your solution does not always work; if you attempt a few times you'll see that it fails sometimes. The problem is that
params.items()
does not guarantee the order of the tuples, so sometimes you get the right order, sometimes you don't. One deterministic right solution is to usecollections.OrderedDict
, for example.This comment is hidden because it contains spoiler information about the solution