Nested Arrays & Hashes | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Nested Arrays & Hashes

arr = [5, [9, 4, 6], [8]] puts arr[1][0] I can't figure out why the answer is 9.

4th Nov 2016, 12:02 AM
shawn hinton
shawn hinton - avatar
4 Answers
+ 4
You've got several arrays; in this case, arr[1][0] means you're accesing the first element of the second array.
8th Nov 2016, 8:59 AM
Luis Ricardo
Luis Ricardo - avatar
+ 3
0 1 2 0 5 N N 1 9 4 6 2 8 N N see this
19th Nov 2016, 6:07 AM
Dorian
Dorian - avatar
+ 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.
4th Nov 2016, 1:00 AM
Schindlabua
Schindlabua - avatar
0
cars = { edad: {daniel:16, leyra:15, josue:17}, ciudad: {daniel:"habana", leyra:"habana", josue:"habana"} } puts [:cars][:edad][:daniel]
28th Dec 2020, 6:37 AM
Breaker
Breaker - avatar