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

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

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

android - How to create dynamically Fragment pager adapter -