← Back to Gists

reverse table pairs

📝 Lua
joanhouse
joanhouse · Level 4 ·

Reverses the key-value pairs in a Lua table, swapping each key with its corresponding value.

Lua
function reverseTablePairs(t) local reversed = {} for k, v in pairs(t) do reversed[v] = k end return reversed
end

Comments

No comments yet. Start the discussion.