From: "Jan E." Date: 2012-07-25T10:14:55+09:00 Subject: Re: Help with exercise from Chris Pine's Ruby Book: Sort without using .sort Hi, You have to re-initialize new_unsorted with an empty array for every iteration. Otherwise it will just keep growing. It's also important to note that Ruby's variables are *references*. This means that variable assignment does *not* copy the value from the right variable to the left. Instead, it makes both variables point to the same object. As an example: a = [1, 2] b = a # b points to the same array as a b.pop # this also affects a p a If you want a copy, you have to actually create it: b = a.dup # or a.clone, which is more strict #-------------- word = [ 'beta', 'zeta', 'alpha', 'depha', 'cina', 'emma', 'bonny', 'falco' ] unsorted = word.clone sorted = [] while unsorted.length > 0 new_unsorted = [] smallest = unsorted.pop unsorted.each do |testword| if testword < smallest new_unsorted.push smallest smallest = testword else new_unsorted.push testword end end sorted.push smallest unsorted = new_unsorted end #-------------- The rest is OK. Of course this algorithm is neither efficient nor pretty, but you already said that you just want to get it working. -- Posted via http://www.ruby-forum.com/.