Jump to content
Sign in to follow this  
czardas

Optimized _ArraySort

Recommended Posts

hi,

@not knowing how to go about it, weather i should do a patch job or maybe its easier to get it done with a core function (didn't go through it .. )

so I'm throwing this into the air 
All I figured out for now is that if instances with ":\"  go to end it fixes some case issues (will need to recall: as to why.)
example: sorted list with $iDescending: 

H:\
False
False
False
Downloads
Documents
Control Panel\Network and Internet\Network Connections
C:\Users\
C:\

what can I amend in so all instances with ":\" get glued to the end of the array

TIA

Deye

Share this post


Link to post
Share on other sites

@Deye This question should have been posted in GH&S. Here's a quick and simple method which does not verify whether paths exist, nor does it verify syntax. It might do what you want, or at least give you some ideas.
 

#include <Array.au3>

Local $aTest = _
['H:\', _
'False', _
'False', _
'False', _
'Downloads', _
'Documents', _
'Control Panel\Network and Internet\Network Connections', _
'C:\Users\', _
'C:\']

_ArrayDisplay($aTest, 'Before')

For $i = 0 To UBound($aTest) -1
    If StringRegExp($aTest[$i], '(\A[A-Z]\:\\)') Then
        $aTest[$i] = 'z' & $aTest[$i]
    Else
        $aTest[$i] = 'a' & $aTest[$i]
    EndIf
Next

_ArraySort($aTest)

For $i = 0 To UBound($aTest) -1
    $aTest[$i] = StringTrimLeft($aTest[$i], 1)
Next

_ArrayDisplay($aTest, 'After')

 

Edited by czardas

Share this post


Link to post
Share on other sites

so here is some madness to extract the target from source, sort both arrays independently, and then glue them back together.

#include<array.au3>

local $array = ['H:\' , 'False' , 'False' , 'False' , 'Downloads' , 'Documents' , 'Control Panel\Network and Internet\Network Connections' , 'C:\Users\' , 'C:\']


for $i = 0 to ubound($array) - 1
    $array[$i] = StringReverse($array[$i])
Next

$arraysort = _ArraySort($array , 1)

for $i = 0 to ubound($array) - 1
    $array[$i] = StringReverse($array[$i])
Next

$aFound = _ArrayFindAll($array , ":\", 0 , 0 ,0 , 1)
$extract = _ArrayExtract($array , $aFound[0])
_ArrayInsert($aFound , 0 , ubound($aFound))
_ArrayDelete($array , $aFound)
_ArraySort($array)
_ArraySort($extract)
_ArrayConcatenate($array , $extract)

_ArrayDisplay($array)

 

Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...