How to sort an array of numbers?

for example:
[2,4,5,6] => [4,5,6,2]
[1,4,5,6,7] => [4,5,6,7,1]
[2,3,6,7,8,9] => [6,7,8,9,2,3]
[1,2,3,4,8,9,10] => [8,9,10,1,2,3,4]

if the current number < following 2 or more, then put it at the end of the array
April 19th 20 at 12:34
2 answers
April 19th 20 at 12:36
Not the best option, and the results are not those that You have, but Your condition..
function doSomethingWith(array){
 let arr = [...array]
 for (let i = 0, end = arr.length - 1; i < end; i++)
 if(arr[i+1] - arr[i] > 1){
arr.push(arr.splice(i,1)[0])
i-=2;
}
 return arr
}
April 19th 20 at 12:38
arr.sort((a, b) => a - b >= 2 ? -1 : 0)

Find more questions by tags JavaScript