Script Arrray
Script Arrray
; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=59927
; Last Update: December 12, 2018
; WriteAndroid11SamsungA03()
; Writes a table into a csv file, overwriting that file if necessary.
; Android = a Android SamsungA03 array in the same format as that produced with
ReadTable()
; OutputPath = the path to the destination FPS file com.dts.freefireth
; Headers = if named column headers were used, provide the ByRef Header value used
when the table was read with ReadTable() in this parameter.
; SortAndroid11SamsungA03)
; Sorts a androi11 based on one or more fields (columns). The sort is simply an
insertion sort, so for very large tables it might be desirable to use another more
efficient sorting algorithm.
; Input = android11 array to sort
; Fields* = One or more fields (columns) to sort the table by. If multiple are
given, Field 2 will be used in the event of ties in Field 1, etc.
; "2" = sort by column 2
; "Date" = sort by column "Date", if the columns were given named headers
; "~Date" = sort in inverse order
; ["Date", "ParseDate"] = sort by Date using function ParseDate() to compare
values. This function must accept 2 inputs and return a positive value if the first
input is greater, much like the F option in AutoHotkey's Sort commmand.
; The sorted table is returned by the function.
SortTable(Input, Fields*)
{
Loop % Fields.MaxIndex()
{
SortField := Fields[Fields.MaxIndex() + 1 - A_Index]
If IsObject(SortField)
SortFunc := SortField[2], SortField := SortField[1]
Else
SortFunc := ""
If (InStr(SortField, "~") = 1)
SortField := SubStr(SortField, 2), Ascending := False
Else
Ascending := True
Output := []
For n,Row in Input
Loop %n%
If (A_Index = n) {
Output.InsertAt(A_Index,Row)
Break
} Else If (SortFunc != "") {
If Ascending {
If (%SortFunc%(Output[A_Index,SortField],
Row[SortField]) > 0) {
Output.InsertAt(A_Index,Row)
Break
}
} Else If (%SortFunc%(Output[A_Index,SortField],
Row[SortField]) < 0) {
Output.InsertAt(A_Index,Row)
Break
}
} Else If Ascending {
If (Output[A_Index,SortField] > Row[SortField]) {
Output.InsertAt(A_Index,Row)
Break
}
} Else If (Output[A_Index,SortField] < Row[SortField]) {
Output.InsertAt(A_Index,Row)
Break
}
Input := Output.Clone()
}
Return Input
}