RemoveAdjacentDuplicates
Removes adjacent duplicates from a container.
Syntax
-
RemoveAdjacentDuplicates(L)
-
L
is a linear container
-
-
RemoveAdjacentDuplicates(L, ε)
-
L
is a linear container -
ε
is a non-negative number
-
Description
If L
is a list or some other linear container, then RemoveAdjacentDuplicates(L)
returns L
with all adjacent duplicates removed; each run of identical values is replaced by a single entry of this value.
RemoveAdjacentDuplicates(L, ε)
has the same behaviour, except that floating-point comparisons are made with epsilon ε
.
Examples
v ≔ ❨2, 1, 1, 2, 1, 3, 4, 1, 1, 2, 3, 4, 5, 1, 5, 1, 2, 3, 4, 1❩;
RemoveAdjacentDuplicates(v)
(2, 1, 2, 1, 3, 4, 1, 2, 3, 4, 5, 1, 5, 1, 2, 3, 4, 1)
RemoveAdjacentDuplicates(v, 1.5)
(2, 4, 1, 3, 5, 1, 5, 1, 3, 1)