Jump to content

Recommended Posts

_ArrayReverse work only on 1D array so....

__ReverseArray which work on 1D & 2D Array

#include <Array.au3>

Local $Eg_1[][] = [['A', 1, 11], ['B', 2, 22], ['C', 3, 33], ['D', 4, 44], ['E', 5, 55], ['F', 6, 66], ['G', 7, 77], ['H', 8, 88]]
_ArrayDisplay($Eg_1)
_ArrayDisplay(__ReverseArray($Eg_1))
_ArrayDisplay(__ReverseArray($Eg_1, 2, 5))


Local $Eg_2[] = [1, 2, 3, 4, 5, 6, 7, 8]
_ArrayDisplay($Eg_2)
_ArrayDisplay(__ReverseArray($Eg_2))
_ArrayDisplay(__ReverseArray($Eg_2, 2, 5))


; #FUNCTION# =============================================================================
; Name...........: __ReverseArray
; Description ...:
; ========================================================================================
Func __ReverseArray($o_Array, $o_StartPoint = 0, $o_EndPoint = UBound($o_Array) - 1)
    If Not IsArray($o_Array) Then Return SetError(1)
    If $o_StartPoint < 0 Then Return SetError(1)
    If $o_StartPoint >= $o_EndPoint Then Return SetError(1)
    If $o_EndPoint > (UBound($o_Array) - 1) Then Return SetError(1)

    Local $o_Column = UBound($o_Array, 2)
    If $o_Column <= 1 Then $o_Column = 1

    Local $o_Prefix = ''
    Local $o_Suffix = ''

    If $o_StartPoint > 0 Then _
    $o_Prefix = _ArrayToString($o_Array, ($o_Column <= 1 ? @CRLF : '|'), 0, $o_StartPoint - 1, @CRLF, -1, -1) & @CRLF

    If $o_EndPoint < (UBound($o_Array) - 1) Then _
    $o_Suffix = @CRLF & _ArrayToString($o_Array, ($o_Column <= 1 ? @CRLF : '|'), $o_EndPoint + 1, UBound($o_Array) - 1, @CRLF, -1, -1)

    Local $o_ArrayExt = _ArrayExtract($o_Array, $o_StartPoint, $o_EndPoint, -1, -1)

    Local $o_String = ''
    For $i = UBound($o_ArrayExt) - 1  To 0 Step -1
        $o_String &= _ArrayToString($o_ArrayExt, '|', $i, $i, '|', -1, -1) & @CRLF
    Next
    $o_String = StringTrimRight($o_String, 2)

    Local $x_Array[0][$o_Column]
    Local $o_Temp = $o_Prefix & $o_String & $o_Suffix

    _ArrayAdd($x_Array, $o_Temp, 0, '|')
    Return $x_Array
EndFunc

 

Edited by jugador
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...