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 don't quite understand how logical IF operators are used here. Can someone explain?
thats neat!thanks
@nabramow
you could test it yourself in the console.All it does is convert it to a number, convert to Boolean, then finally convert it back to a number
(operand -> number -> Boolean -> number).
Unary Plus or "+" converts an operand to a number, provided it is in an integer format. E.G.
+"5"
=>5
. The first use of it converts a string integer to an integer. Then second use of it converts the Boolean (true or false) to its integer equivalent; false = 0, true = 1.Logical NOT operator or "!" will return true if the operand is empty or non-functional, and return false if it's not empty or it's functional. In terms of integers, this means it will return false if the integer is not equal to 0. It does this by negating the operand. E.G.
!5
=> false.let's have this in steps:
str2
is a string but contains a number.+str2
converts that strign to a number.!+str2
converts that number to a boolean and inverts. This way it becomes either false if non-zero or true if zero.+!+str2
converts that boolean back to a number, now we have either 0 or 1.So this +!+str2 is just a way to put "give me 0 if str2 is not
"0"
, otherwise give me 1".Would someone mind explaining what the +!+ does? I'm not quite sure what to google for more info.