Compare string if there's at most one wrong character in Lua
snippet in lua

Compare string if there's at most one wrong character in Lua

user1646

function my_compare(w1, w2)
    if w1:len() ~= w2:len() then
        return false
    end
    for i = 1, w1:len() do
        if w1:sub(i, i) ~= w2:sub(i, i) then
            return w1:sub(i + 1) == w2:sub(i + 1)
        end
    end
    return true
end