Advertisement
pacho_the_python

Sorting Numbers

Feb 22nd, 2023
779
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function sorting_numbers(current_arr) {
  2.     current_arr.sort();
  3.     let sorted_arr = [];
  4.     while (current_arr.length > 0) {
  5.         let first_element = current_arr.shift();
  6.         let last_element = current_arr.pop();
  7.         sorted_arr.push(first_element);
  8.         sorted_arr.push(last_element);
  9.     }
  10.     console.log(sorted_arr);
  11. }
  12.  
  13. sorting_numbers([1, 65, 3, 52, 48, 63, 31, -3, 18, 56])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement