Full-time web dev; JS lover since 2002; CSS fanatic. #CSSIsAwesome
I try to stay up with new web platform features. Web feature you don't understand? Tell me! I'll write an article!
He/him
The elements covered by the range are replaced by the assigned value
Negative indexes are used as offsets from the end of the array. So a[-2] is the same as a[a.length - 2], and a[1..-2] is the same as a[1..a.length-2]
When the end index of a range is <= the start index, no values are replaced
a=[:foo,'bar',baz=2]a[1..-1]# 1..-1 is the same as 1..2 because a.length is 3# => ["bar", 2]a[1..-1]='foo'# this is the same as removing "bar" and 2 from a and replacing them with "foo"# => [:foo, "test"]
Started out teaching English at Embry-Riddle.
Graded 10,000 essays.
Lesson learned.
Became a mathematics teacher.
Discovered computing.
Never looked back.
Location
Houston TX
Education
Stetson University: B.A., M.A. in English; M.S. in mathematics
I think what's happening is:
a[-2]
is the same asa[a.length - 2]
, anda[1..-2]
is the same asa[1..a.length-2]
<=
the start index, no values are replacedYes. Good interpretation. (But still weird, I think.)