I am trying to figure out the following:
When I run this in the terminal using Ruby, the string in the array is removed until it is done when I continue typing in a string that is in the saxophone_section
array. But I still want to be able to remove the string from the array when I type in "alto saxophone 1" and because "alto 1" is found in the input string.
How can I do this when a string in an array matches, regardless of the size of an input string?
saxophone_section = ["alto 1", "alto 2", "tenor 1", "tenor 2", "bari sax"]
until saxophone_section == []
puts "Think of sax parts in a jazz big band."
print ">>"
sax_part = gets.chomp.downcase
# this is the part that is confusing me. Trying to figure out the method in which
# a string in the above array matches an input, whether "alto 1" or "alto saxophone 1"
# or "Eb alto saxophone 1" is typed in ("alto 1" is found in all).
# How can I make it true in all three (or more) cases?
saxophone_section.any?(sax_part)
# I am thinking that this bottom parts one could be used? or not?
parts = saxophone_section.map {|sax| sax.gsub(/\s+/m, ' ').strip.split(" ")}
#this is the loop to delete the item in the array:
if saxophone_section.include?(sax_part) == true
p saxophone_section.delete_if{ |s| s == sax_part}
puts "Damn, you're lucky"
else
puts "Woops! Try again."
end
end
puts "You got all parts."