Guest User

Sort Numbers - JavaScript

a guest
Feb 28th, 2020
313
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(num1, num2, num3) {
  2. let firstPosition = Number.MIN_SAFE_INTEGER;
  3. let secondPosition = 0;
  4. let thirdPosition = 0;
  5.  
  6. let waitingPosition = 0;
  7.  
  8. if (num1 > firstPosition) {
  9. firstPosition = num1;
  10. secondPosition = num2;
  11. thirdPosition = num3;
  12. }
  13. if (num2 > firstPosition) {
  14. firstPosition = num2;
  15. secondPosition = num1;
  16. thirdPosition = num3;
  17. }
  18. if (num3 > firstPosition) {
  19. firstPosition = num3;
  20. secondPosition = num1;
  21. thirdPosition = num2;
  22. }
  23.  
  24. if (thirdPosition > secondPosition) {
  25. waitingPosition = secondPosition;
  26. secondPosition = thirdPosition;
  27. thirdPosition = waitingPosition;
  28. }
  29.  
  30. console.log(firstPosition);
  31. console.log(secondPosition);
  32. console.log(thirdPosition);
  33. }
  34.  
  35. solve(-2, 5, 7);
RAW Paste Data