The source code to remove duplicate elements from the array is given below. The given program is compiled and executed successfully.
# Ruby program to remove duplicate
# elements from the array
arr = [10,20,30,40,50,30,10];
res = arr.uniq();
puts "Array elements: \n",arr,"\n";
puts "Uniq Array elements: \n",res,"\n";
In the above program, we created an array arr with some elements. Then we used uniq() method. The uniq() method is used to remove duplicate elements from array and return an array with unique elements. After that, we printed unique elements.
Program/Source Code:
The source code to remove duplicate elements from the array is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we created an array arr with some elements. Then we used uniq() method. The uniq() method is used to remove duplicate elements from array and return an array with unique elements. After that, we printed unique elements.
need an explanation for this answer? contact us directly to get an explanation for this answer