From: Aldric Giacomoni Date: 2010-02-04T05:57:44+09:00 Subject: Re: [Chris Pine] Chapter 7 - Sorting Arrays without .sort Vegard Sandengen wrote: > Greetings, > > I have set myself out on the great task to understand computer > programming, and i concluded to start my journey with Ruby. It seems like > a the easier to learn program etc. > > I have followed Chris Pines online tutorial and now crashed into the > Chapter 7 task of sorting strings by alphabetic order [...] Well, you need to understand what an array is, and what the element of an array is. Then you need to understand what an algorithm is (hint: so far, google seaches are good). Finally, Chris Pine says you need to write a sorting algorithm. This is where it gets tough if you haven't been introduced to any algorithms, or sorting, yet. Start by doing some reading on Wikipedia about sorting algorithms, or just plain sorting. Then you can look up "bubble sort", "quicksort", "tsort" or "turbosort" to get you started. Thankfully, in Ruby, you can just add to an array and make it bigger and bigger, without ever determining a size ahead of time, and you can loop through an array. Supposing you were allowed to use the "sort" method, and that everything in the array is a string, you could do this: array.sort.each { |word| puts word } Sadly, you can't -- so you need to sort it yourself. Good luck! -- Posted via http://www.ruby-forum.com/.