Advertisement
PowerCell46

Sort Numbers JS

Nov 22nd, 2022
775
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function sortNums(first, second, third) {
  2.  
  3. let array = [];
  4. array.push(first, second, third);
  5.  
  6. let smallestNum = 10000;
  7. let biggestNum = -10000;
  8. let biggestNumIndex = 0;
  9. let smallestNumIndex = 0;
  10.  
  11. for(let index = 0; index < Number(array.length); index++) {
  12. let currentNum = array[index];
  13.  
  14. if(currentNum < smallestNum) {
  15. smallestNum = currentNum;
  16. smallestNumIndex = index;
  17. }
  18.  
  19. if(currentNum > biggestNum) {
  20. biggestNum = currentNum;
  21. biggestNumIndex = index;
  22. }
  23.  
  24. }
  25.  
  26. delete array[biggestNumIndex];
  27. delete array[smallestNumIndex];
  28.  
  29. console.log(biggestNum);
  30. console.log(array.join(""));
  31. console.log(smallestNum);
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement