How to rearrange a given sorted array in maximum minimum form with TypeScript

1 Answer

0 votes
const array : number[] = [1, 2, 3, 4, 5, 6, 7, 8, 9];
 
for (let i : number = 0; i < array.length; i += 2) {
    array.splice(i, 0, array.pop());
}
         
console.log(array);
 
 
 

/*
run:
 
[9, 1, 8, 2, 7, 3, 6, 4, 5] 
 
*/

 



answered Sep 10, 2022 by avibootz
...