On Fri, Nov 29, 2013 at 9:25 PM, Adam Tonto <lists / ruby-forum.com> wrote:

> I'm not looking for anyone to GIVE ME the answer/ do homework for me.
> I'm just looking for a turn in the right direction. Here is my code:

:-D :-)  (attack is the best form of defense)

So, the direction...

When iterating through the elements of an Array you can use
"iterators" rather than a while loop.[1]

So if you really need to iterate you should...

array.each do |element|
  # use the "element"
end

And "each" will take care of the array.lenght limit.

Another generic algorithm hint... you don't need to iterate two times
(one for max and one for min).
You can go on checking for max AND min at the same run, this saves you
the half of the time.

But, as Thomas has pointed out, you don't need to iterate.
You can use the instance methods of the Array class to "sort" the
Array and they will probably to the trick in a faster way.[2]

#1 - http://www.public.traineronrails.com/courses/ruby/pages/012-rubyiterators.html
#2 - http://www.ruby-doc.org/core-2.0.0/Array.html

Show us your improved code (with the hints applied) !

Abinoam Jr.