Guest User

Untitled

a guest
Nov 19th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. a <=> b :=
  2. if a < b then return -1
  3. if a = b then return 0
  4. if a > b then return 1
  5.  
  6. function spaceship(val1, val2) {
  7. if ((val1 === null || val2 === null) || (typeof val1 != typeof val2)) {
  8. return null;
  9. }
  10. if (typeof val1 === 'string') {
  11. return (val1).localeCompare(val2);
  12. }
  13. else {
  14. if (val1 > val2) { return 1 }
  15. else if (val1 < val2) { return -1 }
  16. return 0;
  17. }
  18. }
  19.  
  20. function spaceship(val1, val2) {
  21. if ((val1 === null || val2 === null) || (typeof val1 != typeof val2)) {
  22. return null;
  23. }
  24. if (typeof val1 === 'string') {
  25. return (val1).localeCompare(val2);
  26. } else {
  27. if (val1 > val2) {
  28. return 1;
  29. } else if (val1 < val2) {
  30. return -1;
  31. }
  32. return 0;
  33. }
  34. }
  35.  
  36. Math.sign(a - b);
Add Comment
Please, Sign In to add comment