If I have an array a:
a[a.length]returnsnil. Good.a[a.length, x]returns[]. Good.a[a.length+x, y]returnsnil. Inconsistent with 2.
While this behavior is documented, it seems odd.
Can anybody explain the reasons behind this design?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Consider this
So
a[4, 10]is the slice between the3and the end of the array which is[]Where as
a[4]anda[5, 10]are accessing elements that aren’t in the arrayIt may help to think of the slice points as being between the elements, rather than the elements themselves.
Where
<n>are the points between elements and the start/end of the array.a[4, 10]then becomes a selection of 10 elements, starting from point 4. Whereasa[5, 10]starts from point 5, which is not part of the list.