Merge function in Lua
snippet in lua

Merge function in Lua

user8994

function merge(l1, l2) 
    if #l1 == 0 then
        return l2
    elseif # l2 == 0 then
        return l1
    else
        if l1[1] <= l2[1] then
            local tmp = table.remove(l1, 1)
            local t = merge(l1, l2) 
            table.insert(t, tmp)
            return t
        else 
            local tmp = table.remove(l2, 1)
            local t = merge(l1, l2) 
            table.insert(t, tmp)
            return t
        end 
    end 
end