Home Manual Reference Source Test

lib/compare/number.js

  1. /**
  2. * This method returns a number indicating whether num1 comes before or after or is the same as the num2 in sort order (ascending order)
  3. * 1 num1 comes after num2
  4. * -1 num1 comes before num2
  5. * 0 num1 same as mum2
  6. * @param {Number} num1
  7. * @param {Number} num2
  8. * @return {Number}
  9. */
  10. function number(num1, num2) {
  11.  
  12. if (isNaN(num1) && isNaN(num2))
  13. return 0;
  14. if (isNaN(num1))
  15. return 1;
  16. if (isNaN(num2))
  17. return -1;
  18.  
  19. if (num1 < num2)
  20. return -1;
  21. if (num1 > num2)
  22. return 1;
  23. return 0;
  24. }
  25.  
  26. export default number;