PDA

View Full Version : Checking an array for multiple occurences?


LoneRobot
03-15-2009, 10:31 PM
hello peeps,

say i have an array that contains multiple integers (not necessarily in order), is there a way of checking this array for the multiples and returning the info on how many of each occurence there are -

ie -

#(2,3,6,4,2,3,5,2,5,6,5)

returning the details -

3 instances of 2
2 of 3
1 of 4
3 of 5
2 of 6

cheers!

coren
03-15-2009, 10:56 PM
try this:
vetOriginal=#(2,3,6,4,2,3,5,2,5,6,5)
vetTemp=deepCopy vetOriginal

sort vetTemp

i=vetTemp.count

while i>=1 do
(
pos=findItem vetTemp (vetTemp[i])
format"% instances of %\n"(i-pos+1) (vetTemp[i])
i=pos-1
)

it should work.

cheers

LoneRobot
03-15-2009, 11:11 PM
hi michele,

that's a nice solution, thanks!

CGTalk Moderation
03-15-2009, 11:11 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.