# 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. I seriously love your blog.. Pleasant colors & theme.
Did you build this site yourself? Please reply back as I’m planning
to create my very own website and would like to know where you got
this from or what the theme is named. Many thanks! http://herreramedical.org/azithromycin

5. Hello, I think your website might be having browser compatibility
looks fine but when opening in Internet Explorer, it has some overlapping.

I just wanted to give you a quick heads up! Other then that,
amazing blog! https://hhydroxychloroquine.com/

6. [url=http://bestviagrapills.com/]viagra pills for sale canada[/url]

8. [url=http://eccpharm.com/]over the counter prednisone no prescription[/url]

10. [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]