I have an array of numbers [1,2,2,2,3,4,5]

What I want to do is to sort the array to avoid equal numbers consecutively [1,2,3,2,4,2,5]. but I don't want to delete any number from the array, in the worse case when the duplicated numbers are more than the other numbers I would like to put those that are impossible to merge in other arrays.

```
const original = [1,2,2,2,2,2,2,3,4];
const merged = [];
const rest = [];

```

For example [1,2,2,2,2,2,2,3,4] the result expected should be [2,1,2,3,2,4,2] and another array with [2,2] in the original array I have 6 times 2 and I was able to merge 4 of the six in the rest

```
    const original = [1,2,2,2,2,2,2,3,4];
    const merged = [2,1,2,3,2,4,2];
    const rest = [2,2];

```

I was trying to play with this algorithm but there is no way to get the respected result, this algorithm deletes the duplicates

```
const testArr = [1, 1, 2, 2, 3, 3, 1, 1, 1];
const compress = (arr, len = 0, canDelete = false) => {
   if(len < arr.length){
      if(canDelete){
         arr.splice(len, 1);
         len--;
      }
      return compress(arr, len+1, arr[len] === arr[len+1])
   };
   return;
};
compress(testArr);
console.log(testArr);

```

Any Idea on what is the best way to face this kind of problem?