Q:

Write a Ruby program to remove blank elements from a given array

0

Write a Ruby program to remove blank elements from a given 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 "\nRemove blank element from the above array:\n"
new_color = color.reject { |c| c.empty? }
print new_color 

Output:

Original array:
["Red", "Green", "", "Blue", "White"]
Remove blank element from the above array:
["Red", "Green", "Blue", "White"]

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