Inverter chaves e valores

Published by Helen Yu in

Escreva uma função que inverta as chaves e os valores de um hash. Os valores de entrada são únicos.

Exemplos

invert({ "z" => "q", "w" => "f" })
➞ { "q" => "z", "f" => "w" }

invert({ "a" => 1, "b" => 2, "c" => 3 })
➞ { 1 => "a", 2 => "b", 3 => "c" }

invert({ "zebra" => "koala", "horse" => "camel" })
➞ { "koala" => "zebra", "camel" => "horse" }

Notas

Mantenha a mesma ordem no hash.