Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

Function that takes array and finds unique indexes

$
0
0

Cannot get my head around this...I have an array of X, and in that array each index has 3 parts, I need to find the unique indexes of the main array

 

so main array would be

[0] ???|abc|down

[1] ???|abc|downorflapping

[2] ???|ccc|ccc

[3] ???|ddd|ddd

[4] ???|xyz|down

[5] ???|xyz|unresponsive

 

so that is the array that comes in, and I think I need to break that up in another array and then compare it to each other, but I am not able to get my head around it...the first element does not matter, but if the second element is found anywhere else in the main array, I need to take only one of them, I would like that to be a variable passed, that way I can call it more then once and get the unique values I am looking for...Anyone got an idea?

 

I have tried many different ways but cannot seem to get it right

[autoit]

$aListAlerts[6] = ["???|abc|down", "???|abc|downorflapping", "???|ccc|ccc", "???|ddd|ddd", "???|xyz|down", "???|xyz|unresponsive"]

 

 

 

 

_ArrayDisplay($aListAlerts, 'all alerts')

    Local $aNewArray[2]

    For $x = 0 To UBound($aListAlerts) - 1
        Local $aTestArray = StringSplit($aListAlerts[$x], '|', 2)
        If UBound($aTestArray) <= 1 Then ContinueLoop
        ConsoleWrite($x & '  X  ' & $aListAlerts[$x] & @CRLF)
        For $y = 0 To UBound($aListAlerts) - 1
            If $y = $x Then ContinueLoop
            If StringInStr($aListAlerts[$y], $aTestArray[1]) Then
                Local $aTestArray2 = StringSplit($aListAlerts[$y], '|', 2)
                ConsoleWrite($y & '  Y  ' & $aListAlerts[$y] & @CRLF)
                If UBound($aTestArray2) <= 1 Then ContinueLoop
                If $aTestArray2[2] <> $aTestArray[2] Then

                    If $aTestArray2[2] = 'Down' Then
                        If $aTestArray[2] = 'DownOrFlapping' Then
                            If _ArraySearch($aNewArray, $aListAlerts[$x]) <> @error Then
                            _ArrayAdd($aNewArray, $aListAlerts[$x])
                            ExitLoop
                            EndIf
                        EndIf
                    ElseIf $aTestArray2[2] = 'DownOrFlapping' Then
                        If $aTestArray[2] = 'Down' Then
                            If _ArraySearch($aNewArray, $aListAlerts[$x]) <> @error Then
                            _ArrayAdd($aNewArray, $aListAlerts[$x])
                            ExitLoop
                            EndIf
                        EndIf
                    Else
                        If _ArraySearch($aNewArray, $aListAlerts[$x]) = @error Then
                        _ArrayAdd($aNewArray, $aListAlerts[$x])
                        ExitLoop
                        EndIf
                    EndIf

                EndIf

            EndIf
        Next
    Next

    _ArrayDisplay($aNewArray)

[/autoit]

 

 

edit does not look like tags are working?


Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>