Code: Select all
myArray := [[2, "Quick"]
, [4, "Brown"]
, [3, "Fox"]
, [1, "Jumps"]]
For Each, x In myArray
myResult .= x[1] " " x[2] "`n"
MsgBox % myResult
Thanks1 Jumps
2 Quick
3 Fox
4 Brown
Code: Select all
myArray := [[2, "Quick"]
, [4, "Brown"]
, [3, "Fox"]
, [1, "Jumps"]]
For Each, x In myArray
myResult .= x[1] " " x[2] "`n"
MsgBox % myResult
Thanks1 Jumps
2 Quick
3 Fox
4 Brown
Code: Select all
myArray := {2: "Quick"
, 4: "Brown"
, 3: "Fox"
, 1: "Jumps"}
For i, x In myArray
myResult .= i " " x "`n"
MsgBox % myResult
Code: Select all
myArray := [[2, "Quick"]
,[4, "Brown"]
,[3, "Fox"]
,[1, "Jumps"]]
tObj := {}
For each, arr In myArray
tObj[arr[1]] := arr[2]
myArray := []
For n, w in tObj
myArray.Push([n,w])
For each, arr In myArray
myResult .= arr[1] " " arr[2] "`n"
MsgBox % Trim(myResult)
Thanks for the nice tip
Code: Select all
myArray := [[2, "Quick"]
,[4, "Brown"]
,[3, "Fox"]
,[3, "Over"]
,[1, "Jumps"]]
1 Jumps
2 Quick
3 Over
4 Brown
Pass the elements to a variable, use Sort, parse, split, back to arrays.
Code: Select all
myArray := [[2, "Quick"]
,[4, "Brown"]
,[3, "Fox"]
,[3, "Over"]
,[1, "Jumps"]]
tList := ""
For each, arr In myArray
tList .= arr[1] " " arr[2] "`n"
tList := RegExReplace(tList,"s)^\v+|\v+$")
Sort, tList
myArray := []
Loop, parse, tList, `n, `r
_ := StrSplit(A_LoopField," "), myArray.Push([_[1],_[2]])
For each, arr In myArray
myResult .= arr[1] " " arr[2] "`n"
MsgBox % myResult
thanks for comment
Code: Select all
List<List<string>> myArray =
new List<List<string>> {
new List<string> { "2", "Quick" },
new List<string> { "4", "Brown" },
new List<string> { "3", "Fox" },
new List<string> { "3", "Over" },
new List<string> { "1", "Jump" }};
MessageBox.Show(string.Join("\n",
myArray
.OrderBy(x => x[0])
.ThenBy(x => x[1])
//.ThenByDescending(x => x[1])
.Select(x => x[0] + " " + x[1])));
// 1 Jump
// 2 Quick
// 3 Fox
// 3 Over
// 4 Brown
// 1 Jump
// 2 Quick
// 3 Over
// 3 Fox
// 4 Brown
Very easy with nnnik's nice sort functionI'd like make it like this
Code: Select all
myArray := [[2, "Quick"]
, [4, "Brown"]
, [3, "Fox"]
, [1, "Jumps"]]
sort myArray, (a, b) => a[1] < b[1] ? -1 : a[1] > b[1] ? 1 : 0
For Each, x In myArray
myResult .= x[1] " " x[2] "`n"
MsgBox myResult
Code: Select all
A := new biga()
array := [[2, "Quick"]
, [4, "Brown"]
, [3, "Fox"]
, [1, "Jumps"]]
sortedArray := A.sortBy(array, 1)
msgbox, % A.print(sortedArray)
; => [[1, "Jumps"], [2, "Quick"], [3, "Fox"], [4, "Brown"]]
Code: Select all
array := [{"order": 2, "value": "Quick"}
, {"order": 4, "value": "Brown"}
, {"order": 3, "value": "Fox"}
, {"order": 1, "value": "Jumps"}]
How does one install/use biga.ahk given that AHK is for Windowz and Windowz doesn't have npm installer (AFAIK... noob alert)Chunjee wrote: ↑13 Nov 2019, 11:07I tested this with biga.ahk and it works: https www.npmjs.com /package/biga.ahk Broken Link for safety
I am going to try this. Thanks for suggestion on how to use biga.ahk.Chunjee wrote: ↑13 Nov 2019, 11:07I would recommend the following as easier to work with:in which case sorting by the key "order" is clearer like so: A.sortBy(array, "order")Code: Select all
array := [{"order": 2, "value": "Quick"} , {"order": 4, "value": "Brown"} , {"order": 3, "value": "Fox"} , {"order": 1, "value": "Jumps"}]
I have manually included export.ahk but the following array is not sorting:Chunjee wrote: ↑01 Apr 2021, 16:55if you are not familiar with npm or don't have it installed. You may wish to download the library directly from github. All you need is export.ahk Broken Link for safety which you would #Incude as you would normally a class library.
Code: Select all
Result_Array_Filtered := [{"distance": 10540, "Lat": 40.75423387, "Lon": -73.92452087, "target": "<trkpt lat=""40.75423387"" lon=""-73.92452087""><name>#001</name></trkpt>"}
, {"distance": 47430, "Lat": 40.68004787, "Lon": -73.93168387, "target": "<trkpt lat=""40.68004787"" lon=""-73.93168387""><name>#002</name></trkpt>"}
, {"distance": 1030, "Lat": 40.90804987, "Lon": -73.83052687, "target": "<trkpt lat=""40.90804987"" lon=""-73.83052687""><name>#003</name></trkpt>"}
, {"distance": 3510, "Lat": 40.85642787, "Lon": -73.87724487, "target": "<trkpt lat=""40.85642787"" lon=""-73.87724487""><name>#004</name></trkpt>"}
, {"distance": 144, "Lat": 40.71114687, "Lon": -73.77809887, "target": "<trkpt lat=""40.71114687"" lon=""-73.77809887""><name>#005</name></trkpt>"}]
Result_Array_Filtered_Sorted := A.reverse(A.sortBy(Result_Array_Filtered, "distance"))