-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fruits problem.rb
14 lines (10 loc) · 954 Bytes
/
Fruits problem.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Our fruit guy has a bag of fruits (array of strings) where some fruits are rotten, he wants to replace all the rotten fruits by good ones. For example, given this array ["apple","rottenBanana","apple"] the replaced array should be ["apple","banana","apple"]. Your task is to implement a method that will take as an argument an array of strings containing fruits and should return an array of strings where all the rotten fruits are replaced by good ones.
# Note: If the array is null or empty you should return empty array ([]). The rotten fruit name will be in this format rottenFruitname where is the 1st letter of the fruit name is uppercase. NB: The returned array should be in LOWER case.
def remove_rotten(fruitBasket)
fruitBasket.each do |d|
d.gsub!(/rotten/, '')
d.downcase!
end
end
p remove_rotten(["apple","rottenBanana","kiwi","rottenMango"])
p remove_rotten(["rottenApple", ";rottenAvocado", "rottenApple"])