AreWe

Sorting

Jun 18th, 2020
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. sorting = (arr) => {
  2.     let ascending = arr.sort( (a, b) => { return a - b; } );
  3.     let descending = ascending.slice(0).reverse();
  4.     let result = [];
  5.     let half = Math.ceil(ascending.length / 2);
  6.  
  7.     for(let i = 0; i < half; i++) {
  8.         result.push(descending[i]);
  9.        
  10.         if(descending[i] === ascending[i]) {
  11.             break;
  12.         }
  13.  
  14.         result.push(ascending[i]);
  15.     }
  16.  
  17.     console.log('\n' + result.join(' '));
  18. };
Add Comment
Please, Sign In to add comment