Sort By Key

Send Snippet To: Save this snippet to Code Collector Pro -- view all roger's snippets
language: Other
license: Other

Code for Snippet:

-- "Sorted by key" table iterator 
-- Extracted from
function pairsKeySorted(t, f)
    local a = {}    
    for n in pairs(t) do
        table.insert(a, n)
    table.sort(a, f)
    local i = 0      -- iterator variable
    local iter = function ()   -- iterator function
        i = i + 1
        if a[i] == nil then
            return nil
            return a[i], t[a[i]]
    return iter
comments powered by Disqus


Tags: sort key

Link to this snippet:

Download to Code Collector

To use the direct link to your snippet on either copy the html from the above section or drag the Download to Code Collector to where you would like to use it.

More Info:

Times Viewed: 5
Date Added: 2018-01-09 04:34:18
Last Modified: 2018-01-10 09:54:13

Web Analytics