ArrayDeduplicate procedure

David Thompson dthmpsn1 at uiuc.edu
Fri Mar 21 06:37:51 PDT 2008


>If it was from one of my posts, I can't find in anywhere. Here is a 
>possible solution from the here and now:
>
>ArrayFilter MyArray,MyArray,¶,
>      ?(arraysearch(arrayrange(arrayreverse(MyArray,¶),1,
>      arraysize(MyArray,¶)-seq(),¶),import(),1,¶)=0,import(),"")
>MyArray =arraystrip(MyArray,¶)
>
>The ArrayFilter formula searches the reversed version of the original 
>array from the first element to just before the point in the array we 
>are currently working on using the arraysize(-seq(). If it finds a 
>match it means the same element already exists in the new array so we 
>do not add it. If it does not find a match it imports the current 
>element. The last line strips the empty elements. This should keep 
>the same order as originally presented but remove the duplicates.

Here's one I posted on August 14, 2002.

ArrayFilter 
oldarray,newarray,sep,?(arraysearch(arrayrange(oldarray,1,seq()-1, 
sep),import(),1, sep),"",import())
newarray=arraystrip(newarray,sep)

My version will use the first instance of every 
value, and throw out any that occur later. Gary's 
will use the last instance of every value, and 
throw out any that occur prior.

I got a little fancy in my use of arraysearch(. 
Instead of comparing its value to zero, I just 
used its value as the condition in the ?( 
function. If the value is zero, it will be 
considered "false" and if its value is non-zero, 
it will be "true."

Dave


More information about the Qna mailing list