For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /reference/array/dropRepeats.md.

dropRepeats

Removes consecutively repeated elements from an array using strict equality (===).

Only adjacent duplicates are removed — non-adjacent duplicates are kept. Use uniq to remove all duplicates regardless of position.

Quirks (inherent to ===):

  • NaN !== NaN, so adjacent NaNs are not collapsed.
  • -0 === 0, so adjacent -0 and 0 are collapsed.
  • Object/array elements compare by reference, not structure.
dropRepeats([1, 1, 2, 3, 3, 2, 1])
// [1, 2, 3, 2, 1]

Usage

dropRepeats<T>(array: readonly T[])

Removes consecutively repeated elements from an array using strict equality (===).

Only adjacent duplicates are removed — non-adjacent duplicates are kept. Use uniq to remove all duplicates regardless of position.

Quirks (inherent to ===):

  • NaN !== NaN, so adjacent NaNs are not collapsed.
  • -0 === 0, so adjacent -0 and 0 are collapsed.
  • Object/array elements compare by reference, not structure.
import { dropRepeats } from 'massaman'
// or:  import { dropRepeats } from 'massaman/array'

dropRepeats([1, 1, 2, 3, 3, 2, 1])
// [1, 2, 3, 2, 1]

Parameters

arrayreadonly T[]required

the source array.

Returns

a new array with consecutive duplicate elements removed.

T[]