samedi 19 décembre 2015

Ambiguity with accessing arrays in Ruby

I was doing some koans today and came across something that doesn't really make sense to me... hoping someone can clarify.

array_test = [1, 2, 3, 4]

When I call array_test[3,1] => [4]

When I call array_test[4,1] => []

But then when I call array_test[5,1] => nil

Why is it that "array_test[4,1]" returns [], and "array_test[5,1] returns nil, even though both positions don't exist in the array?

Aucun commentaire:

Enregistrer un commentaire