+ 1

I'm misunderstanding something...

Why would the output be false for the array -1?

8th Aug 2017, 1:42 AM
『Rachel』
『Rachel』 - avatar
5 odpowiedzi
+ 10
@Rachel. a[-1] is used to access the variable in the list from the end. So, a[-1] is the same as a[3] which is false. Similarly, a[-2] =15.88 This flexibility in indexing is very useful when you code.
8th Aug 2017, 2:25 AM
Pixie
Pixie - avatar
+ 7
Could you explain; post a code maybe?
8th Aug 2017, 2:06 AM
J.G.
J.G. - avatar
+ 1
yes, In the language Ruby, we have the array. arr=[5,"Dave",15.88,false] I am going to skip to the portion that I don't understand the output to, which is puts arr [-1] #false. I could go in circles about why I don't understand. :(
8th Aug 2017, 2:20 AM
『Rachel』
『Rachel』 - avatar
+ 1
Thank you.
8th Aug 2017, 2:26 AM
『Rachel』
『Rachel』 - avatar
+ 1
I also found the note that references your answer. thank you :)
8th Aug 2017, 2:31 AM
『Rachel』
『Rachel』 - avatar