From ac09c98720f30b46a371dcad631f352ce34ef887 Mon Sep 17 00:00:00 2001 From: Travis CI <> Date: Sun, 4 Apr 2021 04:07:12 +0000 Subject: [PATCH] Deploy to GitHub Pages: --- lists.html | 15 ++++++++++++--- modules/core/list.html | 17 +++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/lists.html b/lists.html index a1ee5d18..711a5075 100644 --- a/lists.html +++ b/lists.html @@ -202,19 +202,28 @@ System.print(combined) //> [a, b, c, d, e, f]
The opposite of insert is removeAt. It removes a single element from a
-given position in the list. All following items are shifted up to fill in the
-gap:
To remove a specific value instead, use remove. The first value that
+matches using regular equality will be removed.
In both cases, all following items are shifted up to fill in the gap.
var letters = ["a", "b", "c", "d"]
letters.removeAt(1)
System.print(letters) //> [a, c, d]
+letters.remove("a")
+System.print(letters) //> [c, d]
-The removeAt method returns the removed item:
Both the remove and removeAt method return the removed item:
System.print(letters.removeAt(1)) //> c+
If remove couldn’t find the value in the list, it returns null:
+System.print(letters.remove("not found")) //> null
+
+
If you want to remove everything from the list, you can clear it:
hirsute.clear() diff --git a/modules/core/list.html b/modules/core/list.html index 39a5eca0..5d25d5ac 100644 --- a/modules/core/list.html +++ b/modules/core/list.html @@ -146,6 +146,23 @@ System.print(["a", "c"].insert(1, "b")) //> biterate(iterator), iteratorValue(iterator) #
Implements the iterator protocol for iterating over the elements in the list.
+remove(value) #
+Removes the first value found in the list that matches the given
+value, +using regular equality to compare them. All trailing elements +are shifted up to fill in where the removed element was.+var list = ["a", "b", "c", "d"] +list.remove("b") +System.print(list) //> [a, c, d] ++ +Returns the removed value, if found. +If the value is not found in the list, returns null.
++System.print(["a", "b", "c"].remove("b")) //> b +System.print(["a", "b", "c"].remove("not found")) //> null ++removeAt(index) #
Removes the element at
index. Ifindexis negative, it counts backwards from the end of the list where-1is the last element. All trailing elements