Q:

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

0

Write a Ruby program to remove duplicate elements from a given array.

All Answers

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

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]

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