Jump to content

Sorting a 2D array by version


Recommended Posts

@Malkey ruined my one liner, but maybe this works?

#include <array.au3>

Local $aVersionsAndReleases[4][2] = [["0.2.9.4", "Release #1"], ["0.2.9.21", "Release #4"], ["0.2.9.11", "Release #3"], ["0.2.9.5", "Release #2"]]

_ArraySort($aVersionsAndReleases, 1)

for $i = 1 to ubound($aVersionsAndReleases) - 1


If StringSplit($aVersionsAndReleases[$i][0] , "." , 2)[0] = StringSplit($aVersionsAndReleases[$i - 1][0] , "." , 2)[0] AND StringSplit($aVersionsAndReleases[$i][0] , "." , 2)[1] = StringSplit($aVersionsAndReleases[$i - 1][0] , "." , 2)[1] AND StringSplit($aVersionsAndReleases[$i][0] , "." , 2)[2] = StringSplit($aVersionsAndReleases[$i - 1][0] , "." , 2)[2] AND execute(StringReplace($aVersionsAndReleases[$i][0] , "." , "+")) > execute(StringReplace($aVersionsAndReleases[$i - 1][0] , "." , "+")) Then
_ArraySwap($aVersionsAndReleases , $i , $i - 1)
$i -= $i
EndIf
next

_ArrayDisplay($aVersionsAndReleases)

 

 

Edited by iamtheky

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

Link to comment
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
 Share

×
×
  • Create New...