From: Brian Candler Date: 2012-07-30T16:47:17+09:00 Subject: Re: Help with exercise from Chris Pine's Ruby Book: Sort without using .sort Deborah Wyatt wrote in post #1070650: > I used to program back in the 80s and my method is totally different > from what most people would do now, but I wanted to share how I solved > the problem. There are a lot of easier ways, but this does work. Yes, this is a perfectly good selection sort. I'd just make a couple of comments: (1) In the first loop, you assign to the variable 'i', but never use the value; later you re-assign to 'i' in the second loop. Similarly, at the end of the second loop you decrement 'i', but never use that value. The initial assignment 'j = 0' is also superfluous. So you may as well just delete all those lines. (2) You could use more descriptive variable names than "words2", "i", "j" to make your code easier to understand (3) As you progress, you'll find neat little tricks in ruby to simplify the code, e.g. you only need to keep a_index because you can use the return value of delete_at: words2.push words.delete_at(a_index) Regards, Brian. -- Posted via http://www.ruby-forum.com/.