1.

Write a function that sorts the keys in a hash by the length of the key as a string. For instance, the hasht :

Answer» HSH.keys.map(&:to_s).sort_by(&:LENGTH

or: 

hsh.keys.collect(&:to_s).sort_by { |key| key.length } 

or : 

DEF key_sort hsh  hsh.keys.collect(&:to_s).SORT { |a, b| a.length <=> b.length } end


Discussion

No Comment Found