Created
September 17, 2012 12:59
-
-
Save kimenye/3737134 to your computer and use it in GitHub Desktop.
How to detect the first non-repeating character in a line
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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