Working with Nested Arrays

Note: At the moment these exercises require reading up until “Block return values”. You should know how to use the method collect on arrays.

Before you get started, make sure you have your text editor and terminal open, and you have navigated to your exercises directory in the terminal. E.g. cd ~/ruby-for-beginners/exercises.

Exercise 7.1

Make a new file nested_arrays-1.rb, and fill in the following line:

numbers = [
  [1, 2, 3],
  [4, 5, 6],
  [7, 8, 9]
]
# your code goes here
p sums

So that you get the following output:

[6, 15, 24]

Show solution

Exercise 7.2

Make a new file nested_arrays-2.rb, and fill in the following line:

Fill in the following line

numbers = [
  [1, 2, 3],
  [2, 2, 2],
  [3, 2, 1]
]
# your code goes here
lines.each { |line| puts line }

So that you get the following output:

* ** ***
** ** **
*** ** *

Show solution