mirror of
https://github.com/TheAlgorithms/Ruby
synced 2024-12-27 21:58:57 +01:00
code cleanup
This commit is contained in:
parent
0c1892d4ef
commit
984477c24c
1 changed files with 9 additions and 9 deletions
|
@ -1,30 +1,30 @@
|
||||||
# A ruby program to find max from a set of elements
|
# A ruby program to find max from a set of elements
|
||||||
|
|
||||||
# This find_max method will return the max element out of the array
|
# This find_max method will return the max element out of the array
|
||||||
def self.find_max(*array)
|
def find_max(*array)
|
||||||
max = array[0]
|
max = array[0]
|
||||||
array.each do |a|
|
array.each do |a|
|
||||||
if a >= max
|
if a >= max
|
||||||
max = a
|
max = a
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return "The Max of the following elements #{array} is #{max}."
|
"The Max of the following elements #{array} is #{max}."
|
||||||
rescue
|
rescue
|
||||||
return "Error: Please provide number only!"
|
"Error: Please provide number only!"
|
||||||
end
|
end
|
||||||
|
|
||||||
# Max method will return the maximum element from the set of input elements provided
|
# Max method will return the maximum element from the set of input elements provided
|
||||||
def self.predefined_max(*array)
|
def predefined_max(*array)
|
||||||
return "The Max of the following elements #{array} is #{array.max}."
|
"The Max of the following elements #{array} is #{array.max}."
|
||||||
rescue
|
rescue
|
||||||
return "Error: Please provide number only!"
|
"Error: Please provide number only!"
|
||||||
end
|
end
|
||||||
|
|
||||||
# Sort method will sort the elements in ascending order. Last method will return the end element out of the array
|
# Sort method will sort the elements in ascending order. Last method will return the end element out of the array
|
||||||
def self.predefined_sort_last_max(*array)
|
def predefined_sort_last_max(*array)
|
||||||
return "The Max of the following elements #{array} is #{array.sort.last}."
|
"The Max of the following elements #{array} is #{array.sort.last}."
|
||||||
rescue
|
rescue
|
||||||
return "Error: Please provide number only!"
|
"Error: Please provide number only!"
|
||||||
end
|
end
|
||||||
|
|
||||||
# Using find_max
|
# Using find_max
|
||||||
|
|
Loading…
Reference in a new issue