Socrathes Posted June 28, 2021 Posted June 28, 2021 Hello, #include <array.au3> Global $test[4][3] = [["Jax",100,3],["Jade",50,1],["Jaquie",70,0],["Sonya",80,2]] _ArrayDisplay($test) Is there a quick way of sorting the array in ascending order with the values from column three? thanks in advance
Moderators JLogan3o13 Posted June 28, 2021 Moderators Posted June 28, 2021 (edited) Define "quick way"? Quicker than _ArraySort? _ArraySort($test, Default, Default, Default, 2) Edited June 28, 2021 by JLogan3o13 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
Socrathes Posted June 28, 2021 Author Posted June 28, 2021 "arraysort would do fine but i have not managed to sort in ascending order with it.
Luke94 Posted June 28, 2021 Posted June 28, 2021 @JLogan3o13's solution works fine for me? #include <array.au3> Global $test[4][3] = [["Jax",100,3],["Jade",50,1],["Jaquie",70,0],["Sonya",80,2]] _ArraySort($test, Default, Default, Default, 2) _ArrayDisplay($test) Output:
Luke94 Posted June 28, 2021 Posted June 28, 2021 Ascending: _ArraySort($test, 0, Default, Default, 2) Descending: _ArraySort($test, 1, Default, Default, 2)
Socrathes Posted June 28, 2021 Author Posted June 28, 2021 strangely, "arraysort" did not work for my array with 1000 entries. it works with this test array😅
Luke94 Posted June 28, 2021 Posted June 28, 2021 I think _ArraySort sorts in alpha-numeric order - That may be why your array with 1000 entries didn't appear to be sorted. After running this: #include <Array.au3> Global $g_eaNames[4] = [ 'Jax', 'Jade', 'Jaquie', 'Sonya' ] Global $g_aArray[0][3] For $i = 1 To 1000 Step 1 Local $sName = $g_eaNames[Random(0, (UBound($g_eaNames) - 1), 1)] Local $iInteger1 = Random(1, 100, 1) Local $iInteger2 = Random(1, 1000, 1) _ArrayAdd($g_aArray, $sName & Chr(124) & _ $iInteger1 & Chr(124) & _ $iInteger2) Next _ArraySort($g_aArray, 0, Default, Default, 2) _ArrayDisplay($g_aArray) The Output was: Notice how 1000 is before 102.
Moderators JLogan3o13 Posted June 28, 2021 Moderators Posted June 28, 2021 See this post for actually adding elements as numbers, to avoid the sorting issue above: "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
Socrathes Posted June 28, 2021 Author Posted June 28, 2021 this is exactly what happened, what can be done about it
Moderators JLogan3o13 Posted June 28, 2021 Moderators Posted June 28, 2021 2 hours ago, Socrathes said: thx Does this mean you were able to resolve your issue? "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
Socrathes Posted July 12, 2021 Author Posted July 12, 2021 On 6/28/2021 at 9:09 PM, JLogan3o13 said: oes this mean you were able to resolve your issue? yes
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