Invertir claves y valores

Published by Helen Yu in

Escribe una función que invierta las claves y los valores de un hash. Los valores de entrada son únicos.

Ejemplos

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

Conserva el mismo orden en el hash.