4 ms·
I wonder what the behavior of scores[-2] = 4! is. Or, for that matter, of scores[-1.1] = 4! (Assuming that -2 and -1.1 haven’t been deleted.)
by layer8 3y ago
I wonder what the behavior of
scores[-2] = 4!
is. Or, for that matter, of
scores[-1.1] = 4!
(Assuming that -2 and -1.1 haven’t been deleted.)
- humbugtheman 3y agoThe first one would place 4 at the start of the array. So would the second one. If you did the first, then the second one, two 4s would be placed at the start.
- layer8 3y agoBut arrays start at -1. How would that work?
- humbugtheman 3y agoYou can insert items before the start
- layer8 3y agoSo it’s not invariably true that arrays start at -1? They only start at -1 after an array literal assignment? You need to update the language description! ;)
- barnabee 3y agoPerhaps they start at -1 and proceed in both directions
- cdcarter 3y agoconst var scores = [3, 2, 5]! scores[0.5] = 4 print(scores) //[3, 2, 4, 5]! scores[-2] = 10 print(scores) //[10, 3, 2, 4, 5] print(scores[-1]) // 10 is how I interpret the spec, but I did not run this through the reference compiler yet.