On Nov 29, 2013, at 7: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:
>=20
> =
________________________________________________________________________
>=20
> array =3D [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
> min =3D 0
> max =3D 0
> x =3D 0
> i =3D array.length - 1
>=20
> while x < array.length - 1
>  if array[x] > array[x - 1]
>    max =3D x
>  end
>  x+=3D1
> end
>=20
> while i > 0 array.length - 1
>  if array[i] < array[i + 1]
>    min =3D i
>  i-=3D1
>  end
> end
>=20
> puts "Min is: #{min}."
> puts "Max is: #{max}."
>=20
> =
________________________________________________________________________
>=20
> --=20
> Posted via http://www.ruby-forum.com/.

If efficiency isn't an issue then you could take advantage of the =
Enumerable module which an Array will already have included=85

ratdog:~ mike$ pry
[1] pry(main)> array =3D [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
=3D> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
[2] pry(main)> puts "Min is: #{array.min}";
Min is: 1
[3] pry(main)> puts "Max is: #{array.max}";
Max is: 10

Hope this helps,

Mike

--=20

Mike Stok <mike / stok.ca>
http://www.stok.ca/~mike/

The "`Stok' disclaimers" apply.