Mechaflash Posted September 14, 2012 Share Posted September 14, 2012 Has someone created a snippet or UDF to Sort a 2D array by values of two columns? For example, array looks like this. [10, 10] [20, 10] [10, 0] [20, 0] I want to sort by column one AND THEN by column two so it looks like [10, 0] [10, 10] [20, 0] [20, 10] Using the _ArraySort() only allows you to sort by a single column, so the data would come out like [10, 10] [10, 0] [20, 10] [20, 0] If no one has a UDF/snippet already made, I'll create one, but just wanted to make sure I'm not wasting my time if it's already out there. Spoiler “Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.” Link to comment Share on other sites More sharing options...
DicatoroftheUSA Posted September 14, 2012 Share Posted September 14, 2012 I haven't tried it. but you probably could sort the first column. Then examine the array to find the start and end of each series in the first column assign it to start and end. specify the second column with its start and end. #Include <Array.au3> _ArraySort(ByRef $avArray[, $iDescending = 0 [, $iStart = 0 [, $iEnd = 0 [, $iSubItem = 0]]]]) Statism is violence, Taxation is theft. Autoit Wiki Link to comment Share on other sites More sharing options...
Mechaflash Posted September 14, 2012 Author Share Posted September 14, 2012 <------------ DummyI haven't tried it. but you probably could sort the first column. Then examine the array to find the start and end of each series in the first column assign it to start and end. specify the second column with its start and end.I didn't even think about that... XD Spoiler “Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.” Link to comment Share on other sites More sharing options...
DicatoroftheUSA Posted September 14, 2012 Share Posted September 14, 2012 Everyone's third eye gets tunnel vision occasional. If it needs to be tight I would modify the _array to dump the start/ends into a second array, so you don't have to go through the array more than necessary. Statism is violence, Taxation is theft. Autoit Wiki Link to comment Share on other sites More sharing options...
UEZ Posted September 14, 2012 Share Posted September 14, 2012 Something like that? -> Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Thopaga Posted November 1, 2012 Share Posted November 1, 2012 You could try this one: Spoiler Sort a multi-dimensional array with multiple sort columns. Max 9 dimensions. Link to comment Share on other sites More sharing options...
Spiff59 Posted November 2, 2012 Share Posted November 2, 2012 Or this... Global $sorted = 0, $tmp _ArraySort($aArray, 0, 1, 0, 0) ; sort on column 0 While $sorted = 0 ; sub-sort on column 1 $sorted = 1 For $x = 1 to $aArray[0][0] -1 If $aArray[$x][0] = $aArray[$x + 1][0] _ And $aArray[$x][1] > $aArray[$x + 1][1] Then $tmp = $aArray[$x + 1][1] $aArray[$x + 1][1] = $aArray[$x][1] $aArray[$x][1] = $tmp $sorted = 0 EndIf Next WEnd you'd need to make a minor mod or two for a 0-based array and flip the ">" to a "<" were you sorting descending Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now