Algosim documentation: RemoveAdjacentDuplicates

RemoveAdjacentDuplicates

Removes adjacent duplicates from a container.

Syntax

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)

See also