samedi 9 mai 2020

Can someone please let me know where i was wrong. why am i not getting the right answer

Given two strings, word and key, how can I write a method sequence_search(word, key) that returns true (else false) if the characters in key appear in the same order (but not necessarily contiguous) in word?

def sequence_search(word, key)
       new = key.chars
        arr = []
        i = 0
        while i < word.length
        if word[i].include?(key)
        arr >> word[i]
          end
          i+= 1
          end
            if arr.join == key  # line raising exception
            return true
          end
          return false
          end
        end
    sequence_search("arcata", "cat") #=> true
    sequence_search("c1a2t3", "cat") #=> true
    sequence_search("cta", "cat")    #=> false
    sequence_search("coat", "cat")   #=> true

Aucun commentaire:

Enregistrer un commentaire