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();
  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=]brand name cialis canada[/url] [url=]tadalafil 2.5 mg price india[/url] [url=]price of ventolin[/url] [url=]tadalafil 30mg tablet[/url] [url=]sildenafil 5 mg[/url] [url=]viagra cost australia[/url] [url=]cost of tadalafil 20 mg[/url] [url=]cheap cialis 20mg pills[/url] [url=]tadalafil tablets online india[/url] [url=]modafinil paypal[/url]

  2. [url=]buy tadalafil 5mg online[/url] [url=]ivermectin lotion for scabies[/url] [url=]ivermectin 4 mg[/url] [url=]lasix drug for sale[/url] [url=]viagra 300mg price[/url] [url=]viagra 100mg india price[/url] [url=]buy tadalafil 20mg[/url] [url=]how can i get cheap cialis[/url]

  3. [url=]buy cialis brand canada[/url] [url=]prozac capsule 20mg[/url] [url=]glucophage[/url] [url=]ivermectin syrup[/url] [url=]buy generic cialis online in usa[/url] [url=]hydroxychloroquine brand name[/url] [url=]tadalafil 5mg tablets in india[/url]

  4. [url=]ivermectin 400 mg brands[/url] [url=]cheap cialis pills for sale[/url] [url=]nolvadex 10mg tablets price[/url] [url=]prednisone 20mg buy online[/url] [url=]viagra pharmacy prices[/url] [url=]viagra for sale in uk cheap[/url] [url=]25 mg viagra cost[/url]

  5. [url=]furosemide 10 mg canada[/url] [url=]cost viagra[/url] [url=]viagra mexico cost[/url] [url=]stromectol price[/url] [url=]online pharmacy cialis[/url] [url=]sildenafil tablets 100mg uk[/url] [url=]sildenafil online price[/url] [url=]ivermectin india[/url] [url=]10 mg prednisone[/url] [url=]generic cialis for sale in usa[/url]


Leave a Comment