Sunday, July 19, 2009

Hint #3 for my_sort

Hi,

Here's the 3rd hint.

You can iterate backwards over an array with the following code:

def reverse_each(arr)
(arr.size - 1).downto(0) { |i| print arr[i] }
end

reverse_each([3, 2, 1]) # 123

One question about the code above: why did I write (arr.size - 1)?

Look for hint #4 later today.

Glenn

No comments:

Post a Comment