Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(arr){
- let sorted = arr.sort(compareNumbers);
- let final = []
- function compareNumbers(a, b)
- {
- return a - b;
- }
- const sortLent = sorted.length;
- while(final.length < sortLent){
- if(sorted.length > 1){
- final.push(sorted[sorted.length - 1]);
- final.push(sorted[0]);
- sorted.pop(); //Remoe first element
- sorted.shift(); //Remoe last one
- } else {
- final.push(sorted[0]);
- }
- }
- console.log(final.join(' '));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement