sign.js 314 B

123456789101112131415
  1. var toNumber = require('../lang/toNumber');
  2. /**
  3. * Get sign of the value.
  4. */
  5. function sign(val) {
  6. var num = toNumber(val);
  7. if (num === 0) return num; // +0 and +0 === 0
  8. if (isNaN(num)) return num; // NaN
  9. return num < 0? -1 : 1;
  10. }
  11. module.exports = sign;