Ruby Array Exercises: Remove duplicate elements from a given array
Ruby Array: Exercise-6 with Solution
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
Original array: [1, 2, 3, 4, 1, 2, 2, 3, 5, 6] Array with unique elements: [1, 2, 3, 4, 5, 6]
Ruby Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a Ruby program to compute the sum of elements in a given array.
Next: Write a Ruby program to check two given arrays of integers and test if they have the same first element or they have the same last element. Both arrays length must be 1 or more.
What is the difficulty level of this exercise?
- New Content published on w3resource:
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework