# finding dupes and how many of them in an array

## Recommended Posts

So I am making this whole crazy program for my teacher and I have an array of clubs and I need to know which club shows up the most and how many times they show up. I got something working, not to sure how it works just that it works, horribly.

So what I am asking is if there is an easier way/better way to do this.

```#Include <Array.au3>
#Include <string.au3>

dim \$aClubs[11] = ["fighting mongoose", "fatdood", "fighting mongoose", "team awsome", "teem bad", "fighting mongoose", "teem gamming", "teem bad", "fighting mongoose", "fighting mongoose", "teem bad"]

dim \$club[UBound(\$aClubs)][2]
;~ \$club[0][0] = \$aClubs[0]
;~ _ArrayDelete(\$club, 0)
;~ _ArrayDisplay(\$club)
for \$u = 0 to UBound(\$aClubs)-1;i have no idea whats going on here
for \$y = 0 to UBound(\$aClubs)-1
if \$aClubs[\$u] = \$aClubs[\$y] Then
if \$club[\$y][0] = "" then \$club[\$y][0] = \$aClubs[\$u]
\$club[\$y][1] += 1
EndIf
Next
Next

;~ _ArrayDisplay(\$club, "b4sort")
_ArraySort(\$club)
;~ _ArrayDisplay(\$club, "baftersort")

dim \$last, \$todelete
for \$i = 0 to UBound(\$club)-1
if \$club[\$i][0] = \$last then
\$todelete &= \$i&","
EndIf
\$last = \$club[\$i][0]
Next

;~ MsgBox(0, "", \$todelete)
\$todelete = StringTrimRight(\$todelete, 1)
\$todelete = _StringReverse(\$todelete)

;~ MsgBox(0, "", \$todelete)

\$str = StringSplit(\$todelete, ",")

;~ _ArrayDisplay(\$str)

for \$i = 1 to \$str[0]
_ArrayDelete(\$club, \$str[\$i])
Next

_ArrayDisplay(\$club, "DONE")
;then just go through like everything else and do ties but this is all i need right now```

##### Share on other sites

```#Include <Array.au3>

dim \$aClubs[11] = ["fighting mongoose", "fatdood", "fighting mongoose", "team awsome", "teem bad", "fighting mongoose", "teem gamming", "teem bad", "fighting mongoose", "fighting mongoose", "teem bad"]
dim \$aResult[1][2]

_ArraySort(\$aClubs)

;check element to next element, up to second last element against last element
for \$i = 0 to UBound(\$aClubs) - 2
if \$aClubs[\$i] <> \$aClubs[\$i+1] then
if \$aResult[UBound(\$aResult)-1][0] <> "" then ReDim \$aResult[UBound(\$aResult)+1][2]
\$aResult[UBound(\$aResult)-1][0] = \$aClubs[\$i]
\$aResult[UBound(\$aResult)-1][1] = 0
endif
Next

;check last element of \$aClub against second last element
if \$aClubs[UBound(\$aClubs)-2] <> \$aClubs[UBound(\$aClubs)-1] then
if \$aResult[UBound(\$aResult)-1][0] <> "" then ReDim \$aResult[UBound(\$aResult)+1][2]
\$aResult[UBound(\$aResult)-1][0] = \$aClubs[UBound(\$aClubs)-1]
\$aResult[UBound(\$aResult)-1][1] = 0
endif

_ArrayDisplay(\$aResult)

for \$i = 0 to UBound(\$aClubs) - 1
for \$y = 0 to UBound(\$aResult) - 1
if \$aResult[\$y][0] = \$aClubs[\$i] Then
\$aResult[\$y][1] += 1
endif
Next
Next

_ArrayDisplay(\$aResult)```

Edited by KaFu

OS: Win10-1803 - 64bit - German, AutoIt Version: 3.3.14.5, AutoIt Editor: SciTE, Website: http://www.funk.eu, My unsolved Questions: Get default Window Size and Position, Rotate display by 270 degrees, Get Systray Icons, ...

##### Share on other sites

Awesome! thank you so much KaFu!

## Create an account

Register a new account