From: "Jan E." Date: 2012-03-17T19:53:09+09:00 Subject: Re: Sorting Algorithm Hi, There are two errors in your code. First, the line array.push unsortedarray[0..unsortedarray.length] does not what you expect. It does not append the elements of "unsortedarray" to "array" but rather "unsortedarray" itself. So after the first run of the inner while loop you end up with array == [['a', 'b', 'c', 'd']]. And this will break your algorithm. Since you want the *elements* appended, you have to unpack "unsortedarray" first: array.push *unsortedarray However, this is a very complicated and inefficient solution in the first place. Why not simply make "array" a reference to "unsortedarray"? array = unsortedarray Arrays are no physical objects, you don't have to actually empty and refill them. Simply overwrite the reference. The second error is that you forgot to reset "unsortedarray": unsortedarray = [] I thinks that's all. However, you should replace the placeholder with the actual length of the original array. Imagine "array" as having many billions of entries. It would be insane to store the whole array in memory just for its length. And you should replace array[x] < array[y] with array[x] <= array[y]. This will make the algorithm stable (entries with the same search key will remain in their original order). Your code is actually similar to Selection Sort. -- Posted via http://www.ruby-forum.com/.