Module:Sandbox/Erutuon/Temperature difference

function get_numbers(frame)
    parameter_1 = frame.args[1]
    parameter_2 = frame.args[2]
    
    high = {}
    low = {}
    for number in parameter_1:gmatch('%-?%d+%.%d') do
        table.insert(high, number)
    end
    
    for number in parameter_2:gmatch('%-?%d+%.%d') do
        table.insert(low, number)
    end
    return high, low
end

function table_cell(number)
    return "\n| " .. number
end

function print_table(frame)
    get_numbers(frame)
    output = "{| class=\"wikitable nowrap\""
    table_row = "\n|-\n! "
    output = output .. table_row .. "high"
    
    for i = 1, #high do
        output = output .. table_cell(high[i] .. "  °F")
    end
    
    output = output .. table_row .. "difference"
    
    for i = 1, #high do
        output = output .. table_cell(tonumber(high[i]) - tonumber(low[i]) .. "  °F")
    end
    
    output = output .. table_row .. "low"
    
    for i = 1, #low do
        output = output .. table_cell(low[i] .. "  °F")
    end
    
    output = output .. "\n|}"
    return output
end

return { print_table = print_table }