How can I find the first non-recurring letter of a string in Ruby? -


i have string "teststring". want find first non-recurring character in ruby.

i have python code:

def first_non_repeat_character(teststring)     unique=[]     repeated=[]     character in teststring:         if character in unique:             unique.remove(character)             repeated.append(character)         else:             if not character in repeated:                 unique.append(character)     if len(unique):         return unique[0]     else:          return false 

def first_non_repeat_character(string)   string.chars.find { |character| string.count(character) == 1 } end  first_non_repeat_character('teststring') # => "e" 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -