Write a Ruby program to remove blank elements from a given array.
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"]
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer