Module:Shared: Difference between revisions

Add function for sorting dictionaries
m (Add splitString param to trim whitespace)
(Add function for sorting dictionaries)
Line 50: Line 50:
end
end


-- Function to sort a dictionary-like structure where items are added like tbl['key'] = value
-- We need to turn this structure into a table first, in order to sort it.
function p.sortDictionary(dict, comparer)
local sortedTable = {}
    for k, v in pairs(dict) do
        table.insert(sortedTable, {key = k, value = v})
    end
   
    table.sort(sortedTable, comparer)
   
    return sortedTable
end


--General purpose function for going through a table after sorting based on a custom sort order
--General purpose function for going through a table after sorting based on a custom sort order
914

edits