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 herep sums
So that you get the following output:
[6, 15, 24]
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 herelines.each { |line| puts line }
So that you get the following output:
* ** ***** ** ***** ** *
当前内容版权归 rubymonstas 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 rubymonstas .
