forked from Mirror/wren
Reverse the argument order of List.insert
The previous order, insert(element, index), was counter-intuitive. I'm not aware of any list API that uses this order. I've checked: * Ruby Array.insert(index, obj...) * JavaScript array.splice(start, deleteCount[, item1[, item2[, ...]]]) * C++ / QList::insert(int i, const T & value) * C++ / std::vector::insert * Lua table.insert (list, [pos,] value) * C# List<T>.Insert(int index, T item) * Java Interface List<E>.add(int index, E element) * Python list.insert(i, x) So it seemed to me more like an oversight in Wren.
This commit is contained in:
@ -17,7 +17,7 @@ Removes all items from the list.
|
||||
|
||||
The number of items in the list.
|
||||
|
||||
### **insert**(item, index)
|
||||
### **insert**(index, item)
|
||||
|
||||
**TODO**
|
||||
|
||||
|
||||
@ -71,10 +71,10 @@ use `add` to append a single item to the end:
|
||||
You can insert a new element at a specific position using `insert`:
|
||||
|
||||
:::dart
|
||||
hirsute.insert("soul patch", 2)
|
||||
hirsute.insert(2, "soul patch")
|
||||
|
||||
The first argument is the value to insert, and the second is the index to
|
||||
insert it at. All elements following the inserted one will be pushed down to
|
||||
The first argument is the index to insert at, and the second is the value to
|
||||
insert. All elements following the inserted one will be pushed down to
|
||||
make room for it.
|
||||
|
||||
It's valid to "insert" after the last element in the list, but only *right*
|
||||
@ -83,9 +83,9 @@ back. Doing so counts back from the size of the list *after* it's grown by one:
|
||||
|
||||
:::dart
|
||||
var letters = ["a", "b", "c"]
|
||||
letters.insert("d", 3) // OK: inserts at end.
|
||||
letters.insert(3, "d") // OK: inserts at end.
|
||||
IO.print(letters) // ["a", "b", "c", "d"]
|
||||
letters.insert("e", -2) // Counts back from size after insert.
|
||||
letters.insert(-2, "e") // Counts back from size after insert.
|
||||
IO.print(letters) // ["a", "b", "c", "e", "d"]
|
||||
|
||||
## Removing elements
|
||||
|
||||
Reference in New Issue
Block a user