How to sort byte array uniquely

I have an byte array with duplicate values. I want to uniquely sort byte array.
Same output is
[{
“TIMESTAMP”: “11-15-2019 at 09:35”,
“STATUS”: " CLOSED",
“DESCRIPTION”: " Case closed "
},
{
“TIMESTAMP”: “11-15-2019 at 09:35”,
“STATUS”: " CLOSED",
“DESCRIPTION”: " Case closed "
},
{
“TIMESTAMP”: “11-15-2019 at 09:35”,
“STATUS”: " CLOSED",
“DESCRIPTION”: " Case closed "
},
{
“TIMESTAMP”: “11-15-2019 at 09:35”,
“STATUS”: " CLOSED",
“DESCRIPTION”: " Case closed "
},
{
“TIMESTAMP”: “11-15-2019 at 09:35”,
“STATUS”: " CLOSED",
“DESCRIPTION”: " Case closed "
},
{
“TIMESTAMP”: “11-15-2019 at 09:35”,
“STATUS”: " CLOSED",
“DESCRIPTION”: " Case closed "
}]

As “STATUS”: " CLOSED" is repeated , i want to sort uniquely.
Is there any way to do this.

That’s not a “byte array”, that looks much more like a slice of maps.

Also what exactly do you want to do? Do you want to deduplicate repeated entries or do you want to get rid of duplicated entries globally even if other entries are inbetween?

What have you tried so far to achieve your goal?

Many of us do not want to do your work from scratch, but prefer to work with your code instead and push it into the right direction.

2 Likes

I want only unique entry. I have tried sort.sort() and sort.strings() to sort the slice.

And as you do not have implemented the sort.Interface, sort.Sort doesn’t work, also as you do not have a slice of strings, sort.String doesn’t work. Nothing unexpected so far.

Also sorting alone is not what you want, as sorting will only sort, leaving duplicates where they are, though after sorting you should be able to trivially apply a deduplication algorithm.

But as you can not implement sort.Interface for a slice of maps, you’ll need to create an intermediate datatype first.

Is there any help document where i can refer , plz share with me

The documentation of the sort package.

Do you need more?

if you have any other reference plz share in the mean time I will check sort package.

Sorry, I have not anything that goes beyond the docs, as I considered them as beeing enough.

At least for the first step.

The deduplication is trivially done in a loop after sorting, if current element is equal to the previous one, drop it, otherwise keep it.

thanks

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.