I'm trying to transform this sort into a unique sort:
const sort = arr => arr.sort((a, b) => a - b);
I tried this:
const uniqSort = arr => {
const breadcrumbs = {};
for(let i =0; i<arr.length; i++){
if(breadcrumbs[arr[i]]){
arr.splice(i,1)
} else {
breadcrumbs[arr[i]] = true;
}
}
return arr.sort((a, b) => a - b);
};
for some reason it doesn't work properly, can anyone know why?
when I input uniqSort([4,2,2,3,2,2,2]);
the output is [2,2,3,4]
instead of [2,3,4]