Array


#1

Hello,
I have a problem on the exercise 10/12. I should do an array equal to 1through 5.

Is it the good answer : my_array =[1…5] or maybe this one : my_array = [1, 2, 3, 4, 5]

Have you an idea. Thank you for advance for the quick answer.


#2

Your first example will not work as expected. Output will be,

[1...5]

The second example, an array literal, will work as expected.

To assign a range to an array,

numbers = (1..5).to_a
puts numbers             # [1, 2, 3, 4, 5]

Note that in Ruby, a..n includes n in the range. a...n excludes n from the range.


#3

Thank you mtf!

I will try it.

See you.

Estelle


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.