How do you get all the unique elements of an array? Is there an array method that do it?
I know there is an array method called “unique()” but this does not actually return the ‘unique’ elements of the array but rather return a ‘unique version of the array’, where all elements are unique.
For example, let’s say the array is,
int array = {2,5,6,5,1};
If you use the unique method, the output is,
{2,5,6,1}
Notice that the array size has reduced to 4. The elements are now unique. Index 4 of the original array has been removed because it is equal to index 1.
This is not what I want.
What I want is to return only the unique elements of the array like this,
{2,6,1}
Notice that the element whose value is 5 is not included since it is not unique within the array.
It’s possible to write a code to do this, but what I’m asking is if there’s already a system task or an existing array method available that do this?
Thanks.
Regards,
Reuben