I have a unique array of items that are duplicated, occurring twice right next to each other, such as:
const arr = ['1', '1', '2', '2', '3', '3']
My goal is to rearrange the array so that all unique values come first followed by their duplicates, like this:
const arr = ['1', '2', '3', '1', '2', '3']
Is there a way to achieve this using the sort()
function or should I explore other methods?
I attempted the following approach but it did not yield the desired results:
const sorted = myDublicatedArray.sort((left, right) => left.index - right.index);