Skip to content

Instantly share code, notes, and snippets.

@adamloo85
Created November 14, 2013 06:56
Show Gist options
  • Save adamloo85/7462583 to your computer and use it in GitHub Desktop.
Save adamloo85/7462583 to your computer and use it in GitHub Desktop.
Returns the first unique character in a string of duplicates, assuming there are unique characters. Note n-squared performance.
def find_char(string)
word = string.split(//)
word = word.find_all { |x| word.count(x) == 1 }
word.first
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment