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.
what if num = 0
the return will -0
your solution not suitable
if number already negative then returning will be positive - * - = +
Yes, it works this way, and your answer would be 7. But it's not what the kata asks.
Wouldn't it be 7? -7 * -1 = 7. Or it doesn't work this way?
What if the input was
-7
?Hi. Could someone please explain to me why isn't it possible just to write an expression
return num * -1 ?
It doesn't work in JavaScript this way?
works.
.
Is that so?
interesting
it's great , but doesnot work with 0 .
Good Job!
unexpectedly ))
I have a pretty long post down there on when JS uses 0 and -0 seperately. https://www.codewars.com/kata/reviews/556b81de1f97c84309000179/groups/556c878ba06de741b0000015#634decb4075de36ffd9ec320 There are also several mathematical systems where the difference between 0 and -0 are significant. The only thing you can defend about -0 not being the right value is only when you treat all numbers in all languages as those other specific mathematical systems that are not under the same axioms of traditional conventional mathematics, and even then you'd have to convince us that Javascript still works the same with those exotic rules.
However, since we live in a universe where zero is zero, of course both are correct values to return and attempting to seperate them would be the wrong thing to do. Fortunately the "i" in my name does not stand for incompetent unlike iElvis's i and I'm just upset that after tens of comments making the same claim of disinformation that has already been debunked by several different users under this solution, this person has to add another one that's more rude and disrespectful than all of them. It sure is hypocritcal for someone being wrong to accuse others of being wrong.
Unihedron is correct. In an ordinary mathematical sense the two signed zeroes in JS are identical (and neither positive nor negative), therefore both are equally correct return values for this kata.
Even if we were to take the binary representation into account, JS itself considers signed zero to be strictly equal to itself, regardless of the sign;
Loading more items...