On Sun, 02 Apr 2006 03:57:21 GMT, Dave Burt <dave / burt.id.au> wrote:

>Jan_K wrote:
>> Solution for the 1st exercise in chapter 8:
>
>You mean chapter 7.
>

I'm actually reading the book and "Arrays and Iterators" is chapter 8.

The book starts with chapter 1 whereas the online tutorial starts with
chapter 0.

Now that I take a look at both it seems like the book is a cleaned-up
and slightly revised version of the tutorial.


Here's the end of chapter 8 from the book:
----------------------------------------------------------------------------------
8.3 A Few Things to Try

Write the program we talked about at the beginning of this chapter,
one that asks us to type as many words as we want (one word
per line, continuing until we just press Enter on an empty line)
and then repeats the words back to us in alphabetical order. Make
sure to test your program thoroughly; for example, does hitting
Enter on an empty line always exit your program? Even on the
first line? And the second? Hint: There√‘ a lovely array method
that will give you a sorted version of an array: sort. Use it!

Rewrite your table of contents program on page 35. Start the
program with an array holding all of the information for your table
of contents (chapter names, page numbers, etc.). Then print out
the information from the array in a beautifully formatted table of
contents.
----------------------------------------------------------------------------------


This the end of the same chapter from the online tutorial:
----------------------------------------------------------------------------------
A Few Things to Try 

Write the program we talked about at the very beginning of this
chapter.
Hint: There's a lovely array method which will give you a sorted
version of an array: sort. Use it! 

Try writing the above program without using the sort method. A large
part of programming is solving problems, so get all the practice you
can! 

Rewrite your Table of Contents program (from the chapter on
methods). Start the program with an array holding all of the
information for your Table of Contents (chapter names, page numbers,
etc.). Then print out the information from the array in a beautifully
formatted Table of Contents. 
----------------------------------------------------------------------------------



Some crucially important differences:


From the online tutorial:
----------------------------------------------------------------------------------
languages = ['English', 'German', 'Ruby']

languages.each do |lang|
  puts 'I love ' + lang + '!'
  puts 'Don\'t you?'
end

puts 'And let\'s hear it for C++!'
puts '...'
----------------------------------------------------------------------------------

From the book:
----------------------------------------------------------------------------------
languages = [' English' , ' Norwegian' , ' Ruby' ]

languages.each do |lang|
  puts ' I love ' + lang + ' !'
  puts ' Don\' t you?'
end

puts ' And let\' s hear it for Java!'
puts ' <crickets chirp in the distance>'
----------------------------------------------------------------------------------