Skip to content

Instantly share code, notes, and snippets.

@kimenye
Created September 17, 2012 12:59
Show Gist options
  • Save kimenye/3737134 to your computer and use it in GitHub Desktop.
Save kimenye/3737134 to your computer and use it in GitHub Desktop.
How to detect the first non-repeating character in a line
def detect_character_that_occurs_only_once line
if !line.nil?
the_char = line.each_char.detect { |char| line.count(char) == 1}
end
the_char
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment