Write a Ruby program to remove duplicate elements from a given array.
nums = [1, 2, 3, 4, 1, 2, 2, 3, 5, 6] print "Original array:\n" print nums print "\n Array with unique elements:\n" new_nums = nums.uniq print new_nums
Output:
Original array: [1, 2, 3, 4, 1, 2, 2, 3, 5, 6] Array with unique elements: [1, 2, 3, 4, 5, 6]
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