Skip to content

Instantly share code, notes, and snippets.

@lsegal
Created March 30, 2010 22:54
Show Gist options
  • Select an option

  • Save lsegal/349717 to your computer and use it in GitHub Desktop.

Select an option

Save lsegal/349717 to your computer and use it in GitHub Desktop.
def uniq_min(list)
shortest, another = nil, nil
list.each do |obj|
another = obj if shortest && obj.length == shortest.length
shortest, another = obj, nil if !shortest || obj.length < shortest.length
end
another ? false : shortest
end
p uniq_min(%w(BBB BB A CCC B DDDD))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment