Javascript Math sign() method

Description

Javascript Math sign() method


Math.sign = function(x) {
  if (x > 0) {
    return 1/*from  w  w  w . j  ava  2 s.  com*/
  } else if (x < 0) {
    return -1
  } else {
    return 0
  }
}

Javascript Math sign()


Math.sign = function(x) {
  if (x > 0) {
    return 1/*  w  ww.  ja  v a2  s  . com*/
  } else if (x < 0) {
    return -1
  } else {
    return 0
  }
}

Javascript Math sign()

Math.sign = function(x) {
  x = +x;//w w w  .j  a va  2  s . c o m
  if (x === 0 || isNaN(x))
    return x;
  return x > 0 ? 1 : -1;
}



PreviousNext

Related