Possible Duplicate:
Number.sign() in javascript
Given some number variable, what is the easiest way to determine it's sign?
I keep ending up with code like this:
var direction = (vector[0] > 0) ? 1: (vector[0] < 0) ? -1: 0;
It seems less than elegant, when all I want is a -1 if the number is negative, 1 if positive and a 0 if it is 0.
By "easiest" I really mean elegant or less typing.
Alternatively, maybe there is a way to increase a value absolutely. Like if the number is negative, then subtract 1 from it, and if it is positive to add one to it. Math.abs() provides the absolute value, but there is no way to convert it back to a signed number once you run Math.abs().