+ 2
Nested Arrays & Hashes
arr = [5, [9, 4, 6], [8]] puts arr[1][0] I can't figure out why the answer is 9.
4 Antworten
+ 4
You've got several arrays; in this case, arr[1][0] means you're accesing the first element of the second array.
+ 3
0 1 2
0 5 N N
1 9 4 6
2 8 N N
see this
+ 2
arr = [5, [9, 4, 6], [8]]
therefor arr[1] == [9, 4, 6], and from this list you take the first element ([0]), which is 9.
0
cars = {
edad: {daniel:16, leyra:15, josue:17},
ciudad: {daniel:"habana", leyra:"habana", josue:"habana"}
}
puts [:cars][:edad][:daniel]