[03 - Collection Types] subscript syntax
aurelien-ldp opened this issue · 2 comments
aurelien-ldp commented
By default the following fails (on my version, at least):
shoppingList[4...6] = ["Bananas", "Apples"]
As explained in the documentation:
You can’t use subscript syntax to append a new item to the end of an array.
This should fix the problem:
shoppingList[3...4] = ["Bananas", "Apples"]
erginbilgin commented
This replaces elements with indices 2, 3, 4 with ["Bananas", "Apples"] therefore it removes one extra element:
shoppingList[2...4] = ["Bananas", "Apples"]
This is the correct way to replace elements with indices 3 and 4:
shoppingList[3...4] = ["Bananas", "Apples"]
Also, this problem is solved in #6
aurelien-ldp commented
My bad, of course you're right ! I've edited my post.