Advertisement
didkoslawow

Untitled

May 15th, 2023
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function sortingNumbers(numbers) {
  2.      const result = [];
  3.      const smallest = numbers.sort((a,b) => a - b).slice(0, Math.ceil(numbers.length / 2));
  4.      const biggest = numbers.sort((a,b) => b - a).slice(0, Math.floor(numbers.length / 2))
  5.      
  6.      for (let i = 0; i < Math.max(smallest.length, biggest.length); i++) {
  7.          result.push(smallest[i]);
  8.          result.push(biggest[i]);
  9.      }
  10.  
  11.      return result;
  12.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement