Ruby only, approximately 10 minutes: Write a method that receives a list of words and one letter, then returns all words from the list that contain that letter. This exercise is intended to assess basic Ruby knowledge, including traversing arrays and strings.
def words_containing_letter(words, letter)
# your implementation
end
words is a list of words.letter is a single letter.Input:
words_containing_letter(["cat", "dog", "bird"], "o")
Output:
["dog"]
Only "dog" contains "o".
Input:
words_containing_letter(["apple", "banana", "pear"], "a")
Output:
["apple", "banana", "pear"]
Each word in the list contains "a".
Input:
words_containing_letter(["red", "blue", "green"], "z")
Output:
[]
None of the words contains "z".