Ruby using enumerables


  • 0
    M
    def find_words(words)
    
    row1 = "qwertyuiop"
    row2 = "asdfghjkl"
    row3 = "zxcvbnm"
    
    words.map do |word|
        word if word.downcase.chars.all? {|letter| row1.include?(letter)} ||
                word.downcase.chars.all? {|letter| row2.include?(letter)} ||
                word.downcase.chars.all? {|letter| row3.include?(letter)}
    end.compact
      
        
    end
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.