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.
Not in this situation.
The problem with
Math.sign
is that it only works on numbers, while we might be comparing arbitrary comparable objects which doesn't admit a numeric rank.It is performing the sign function, which Javascript does not natively support (yet*, although it is being added:
Math.sign(c)
would give the same result in a Javascript environment which supports the new function). You will also get a number's sign if you divide it by its absolute value; since Javascript does support the abs function, you could writec / Math.abs(c)
to get the same result.The ternary statement there is equivalent to writing,
Since it's inline, you can write a statement such as
return a ? b : c
orresult = a ? b : c
and it's much simpler and more concise than writing the equivalent code.*Actually since CodeWars supports ES6 now,
Math.sign
will work in the JS framework. For use in web programming, though, browser support of the feature is still limited.That's an "inline if" or "ternary" statement.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator