Skip to content

Instantly share code, notes, and snippets.

@wmoxam
Created April 2, 2012 15:19
Show Gist options
  • Save wmoxam/b9a81c8ea4ec76abe1cb to your computer and use it in GitHub Desktop.
Save wmoxam/b9a81c8ea4ec76abe1cb to your computer and use it in GitHub Desktop.
Q: In Ruby, the max method returns the largest number in an array of integers. Ex:
[14, 23, 6, 9, 54, 10].max #=> 54
Write an implementation of the max method that accepts an array as it's argument. Do not use the existing .max method
class Testing
puts "enter five number to check the greatest among from that."
a = gets.chomp
b = gets.chomp
c = gets.chomp
d = gets.chomp
e = gets.chomp
array = []
array << a.to_i
array << b.to_i
array << c.to_i
array << d.to_i
array << e.to_i
def self.message(arr)
arr.sort.last
end
puts "the greatest number among the entered number is " + "#{message(array) }"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment