Q:

Write a Ruby program to check whether a value exists in an array

0

Write a Ruby program to check whether a value exists in an array.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

color = ["Red", "Green", "Blue", "White"]
print "Original array:\n"
print color
print "\nCheck if 'Green' in color array!\n"
print color.include? 'Green'
print "\nCheck if 'Pink' in color array!\n"
print color.include? 'Pink'
Output:
Original array:
["Red", "Green", "Blue", "White"]
Check if 'Green' in color array!
true
Check if 'Pink' in color array!
false

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now