Write a ruby program to remove duplicate values in array
class DeleteDuplicateElement
def deleteDuplicateElement
print "Enter the size of array"
size = gets.chomp.to_i
input_array = []
print "Enter the elements of array"
while size > 0 do
input_array.push(gets.chomp)
size = size - 1
end
print "Entered array is: #{input_array}"
input_array.uniq!
print "\nUniq array is: #{input_array}"
end
end
p = DeleteDuplicateElement.new
p.deleteDuplicateElement
Output:
class DeleteDuplicateElement
def deleteDuplicateElement
print "Enter the size of array"
size = gets.chomp.to_i
input_array = []
print "Enter the elements of array"
while size > 0 do
input_array.push(gets.chomp)
size = size - 1
end
print "Entered array is: #{input_array}"
input_array.uniq!
print "\nUniq array is: #{input_array}"
end
end
p = DeleteDuplicateElement.new
p.deleteDuplicateElement
Output:
Enter the size of array 5
Enter the elements of array 22
33
22
11
55
Entered array is: ["22", "33", "22", "11", "55"]
Uniq array is: ["22", "33", "11", "55"]
|
No comments:
Post a Comment