Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function sortingNumbers(numbers) {
- const result = [];
- const smallest = numbers.sort((a,b) => a - b).slice(0, Math.ceil(numbers.length / 2));
- const biggest = numbers.sort((a,b) => b - a).slice(0, Math.floor(numbers.length / 2))
- for (let i = 0; i < Math.max(smallest.length, biggest.length); i++) {
- result.push(smallest[i]);
- result.push(biggest[i]);
- }
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement