Javascript sort an array by biggest and lowest number

I need help with the sorting as i am totally confused what to do. This is the example:

[1, 65, 3, 52, 48, 63, 31, -3, 18, 56] to [-3, 65, 1, 63, 3, 56, 18, 52, 31, 48].
The first element has to be the smallest, the second to be biggest, the third to be the second smallest element, the fourth to be the second biggest element.

What i have tried is:

function solve(arr) {
  var lowestNum = [...arr].sort((a,b) => a-b);
  let biggestNum = [...arr].sort((a,b) => b-a);
  let nums = [];
  let i = 0;
  while (nums.length !== arr.length) {
    nums.push(lowestNum.shift()); lowestNum.pop();
    nums.push(biggestNum.shift()); biggestNum.pop();
    i++;
  }
  return nums;
}
console.log(solve([1, 65, 3, 52, 48, 63, 31, -3, 18, 56]));

However, that is not the way as my exercise requires me to sort.

124 thoughts on “Javascript sort an array by biggest and lowest number”

  1. [url=https://cicialis.com/]brand name cialis canada[/url] [url=https://tadalafilvpill.com/]tadalafil 2.5 mg price india[/url] [url=https://rpipharm.com/]price of ventolin[/url] [url=https://tadalafilab.com/]tadalafil 30mg tablet[/url] [url=https://icviagra.com/]sildenafil 5 mg[/url] [url=https://hotviagraonline.com/]viagra cost australia[/url] [url=https://ebcialis.com/]cost of tadalafil 20 mg[/url] [url=https://cialisur.com/]cheap cialis 20mg pills[/url] [url=https://tadalafileff.com/]tadalafil tablets online india[/url] [url=https://modafinilxc.com/]modafinil paypal[/url]

    Reply
  2. [url=https://tadalafilbestbuy.com/]buy tadalafil 5mg online[/url] [url=https://ivermectinzt.com/]ivermectin lotion for scabies[/url] [url=https://ivermectinop.com/]ivermectin 4 mg[/url] [url=https://wplasix.com/]lasix drug for sale[/url] [url=https://viagrabuycheap.com/]viagra 300mg price[/url] [url=https://viagraconn.com/]viagra 100mg india price[/url] [url=https://tadalafillowprice.com/]buy tadalafil 20mg[/url] [url=https://azcialis.com/]how can i get cheap cialis[/url]

    Reply
  3. [url=http://cialisvii.com/]buy cialis brand canada[/url] [url=http://crmeds.com/]prozac capsule 20mg[/url] [url=http://dbpills.com/]glucophage[/url] [url=http://ivermectinop.com/]ivermectin syrup[/url] [url=http://ordertadalafilpills.com/]buy generic cialis online in usa[/url] [url=http://oxlpharm.com/]hydroxychloroquine brand name[/url] [url=http://cialisexpress.com/]tadalafil 5mg tablets in india[/url]

    Reply
  4. [url=https://ivermectinzt.com/]ivermectin 400 mg brands[/url] [url=https://cialisdf.com/]cheap cialis pills for sale[/url] [url=https://nolvadexpill.com/]nolvadex 10mg tablets price[/url] [url=https://eccpharm.com/]prednisone 20mg buy online[/url] [url=https://sildenafilvtab.com/]viagra pharmacy prices[/url] [url=https://xviagrahot.com/]viagra for sale in uk cheap[/url] [url=https://doviagra.com/]25 mg viagra cost[/url]

    Reply
  5. [url=https://vdphealth.com/]furosemide 10 mg canada[/url] [url=https://sildenafilvtab.com/]cost viagra[/url] [url=https://sildenafilmedicine.com/]viagra mexico cost[/url] [url=https://ivermectinp.com/]stromectol price[/url] [url=https://pharmacylewis.com/]online pharmacy cialis[/url] [url=https://sildenafilzpill.com/]sildenafil tablets 100mg uk[/url] [url=https://sildenafileasy.com/]sildenafil online price[/url] [url=https://ivermectinpn.com/]ivermectin india[/url] [url=https://eccpharm.com/]10 mg prednisone[/url] [url=https://cialisexpress.com/]generic cialis for sale in usa[/url]

    Reply

Leave a Comment