0

Nested Arrays and hashes q

"What is the output of this code? arr = [5, [9, 4, 6], [8]] puts arr[1][0]" how do u get the out put 5? I tried running- assuming 5 is contained in location 0 in the 0 arr. puts arr[0][0] but once running it , result came back as 1

19th Nov 2017, 10:41 AM
KidA
KidA - avatar
2 odpowiedzi
+ 11
You'll use the square bracket notation only when you want to acess an array element. In this case, 5 is an integer. 😉 For example: arr[0] = 5 arr[1] = [9, 4, 6] arr[1][1] = 4 ...
19th Nov 2017, 10:57 AM
Zephyr Koo
Zephyr Koo - avatar
0
Result: 9
6th Jan 2021, 4:13 PM
George Vrettos
George Vrettos - avatar