Ramda.js R.dropRepeats() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
List

Definition

R.dropRepeats(list) returns a new list where every run of equal neighbouring items is collapsed into a single item (official Ramda docs). Items are compared by value with R.equals, and the first item of each run is kept.

Added in v0.14.0: R.dropRepeats is stable — not deprecated, experimental, or non-standard. Note: it only removes repeats that sit next to each other; use R.uniq to remove every duplicate.

Syntax

Call R.dropRepeats. Start with this line.

Ramda
R.dropRepeats(list) (one argument) Type [a] → [a]
CallWhat it does
R.dropRepeats(list) (one argument) Type [a] → [a]Primary signature.
R.dropRepeats(...)Call the list helper.

Prefer import { dropRepeats } from "ramda" when you want a named import.

Library declarations
Ramda
R.dropRepeats(list) (one argument) Type [a] → [a]

Parameters

ParameterDescription
listRequired. The array to clean up (a string works but returns an array)

Return Value

Return ValueDescription
*A new array with each run collapsed to its first item

Ramda Examples

Example 1 — Official Sample

Collapse runs of equal numbers — the sample from the Ramda docs — and see that spread-out repeats stay.

Ramda
console.log(R.dropRepeats([1, 1, 1, 2, 3, 4, 4, 2, 2]));  // [1, 2, 3, 4, 2]
console.log(R.dropRepeats([1, 2, 1]));                    // [1, 2, 1]
Try It Yourself

How It Works

  1. Runs collapse. 1, 1, 1 becomes 1, 4, 4 becomes 4, and 2, 2 becomes 2.
  2. Neighbours only. The second 2 follows a 4, so it is a new run and stays.
  3. No neighbours. In [1, 2, 1] no two equal items touch, so nothing is removed.
  4. New array. Both calls return fresh arrays; the inputs are unchanged.

Example 2 — Keep Only Status Changes

Turn a noisy log of readings into a clean list of changes.

Ramda
const readings = ['idle', 'idle', 'busy', 'busy', 'busy', 'idle'];

const changes = R.dropRepeats(readings);

console.log(changes);          // ['idle', 'busy', 'idle']
console.log(changes.length);   // 3
Try It Yourself

How It Works

  1. Noisy input. The sensor reports the same state many times in a row.
  2. Collapse. R.dropRepeats keeps the first 'idle', the first 'busy', and the final 'idle'.
  3. Order kept. The result reads as a timeline: idle → busy → idle.
  4. Why not uniq? R.uniq would drop the last 'idle' and lose the return to idle.

Example 3 — Equal Objects, Not Just Same References

R.equals compares values, so separate objects with the same content count as repeats.

Ramda
const points = [{ x: 1 }, { x: 1 }, { x: 2 }];

const withEquals = R.dropRepeats(points);
const withStrict = points.filter((p, i) => p !== points[i - 1]);

console.log(withEquals.length);   // 2
console.log(withStrict.length);   // 3
Try It Yourself

How It Works

  1. Two objects. The first two points are separate objects that both look like { x: 1 }.
  2. By value. R.equals sees the same content, so R.dropRepeats keeps only one → 2 items.
  3. By reference. The hand-written !== check sees two different objects and keeps all 3.
  4. Takeaway. Use R.dropRepeats when data comes from JSON or APIs, where equal values are rarely the same object.

Example 4 — Squeeze Repeated Letters

A string goes in, but an array of characters comes out — join it to get text back.

Ramda
console.log(R.dropRepeats('aabbcc'));                // ['a', 'b', 'c']
console.log(R.dropRepeats('bookkeeper').join(''));   // 'bokeper'
Try It Yourself

How It Works

  1. Characters. A string is read one character at a time, like a list.
  2. Array out. The result is always an array, so 'aabbcc' gives ['a', 'b', 'c'].
  3. Squeeze. In 'bookkeeper', oo, kk, and ee each shrink to one letter.
  4. Join. .join('') turns the character array back into the string 'bokeper'.

Example 5 — dropRepeats vs uniq vs dropRepeatsWith

Three ways to remove duplicates — neighbours only, everywhere, or with your own rule.

Ramda
const nums = [1, 1, 2, 2, 1];

console.log(R.dropRepeats(nums));   // [1, 2, 1]
console.log(R.uniq(nums));          // [1, 2]

const sameSize = R.eqBy(Math.abs);
console.log(R.dropRepeatsWith(sameSize, [1, -1, 2, -2, 3]));   // [1, 2, 3]
Try It Yourself

How It Works

  1. dropRepeats. Collapses 1, 1 and 2, 2; the last 1 follows a 2, so it stays.
  2. uniq. R.uniq removes every later duplicate, so the last 1 goes too.
  3. Custom rule. R.eqBy(Math.abs) treats 1 and -1 as the same.
  4. dropRepeatsWith. R.dropRepeatsWith uses that rule, so -1 and -2 are dropped.

Browser & Runtime Support

R.dropRepeats() is plain JavaScript inside Ramda 0.14.0+. It uses a simple loop and R.equals, so it works wherever Ramda loads.

✓ Ramda 0.14.0+ · Any JS runtime

Ramda.js R.dropRepeats()

The UMD build (ramda.min.js) is compiled to ES5 syntax, so it runs in Chrome, Firefox, Safari, and Edge. Via npm it works in Node.js, Deno, and Bun with require or import.

100% With Ramda 0.14+
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
R.dropRepeats() Universal

Bottom line: Safe in any project on Ramda 0.14 or newer. Load ramda.min.js from a CDN in the browser, or npm install ramda for Node, Deno, and Bun. These labs load [email protected].

Frequently Asked Questions

R.dropRepeats(list) returns a new list in which each run of equal neighbouring items is collapsed into one. The official sample R.dropRepeats([1, 1, 1, 2, 3, 4, 4, 2, 2]) returns [1, 2, 3, 4, 2].
No. R.dropRepeats only removes repeats that sit next to each other, so the official sample keeps the second 2. R.uniq removes every later duplicate and returns [1, 2, 3, 4].
It uses R.equals, which compares by value. Two separate objects like { x: 1 } and { x: 1 } count as equal, while 1 and '1' do not. For a custom rule use R.dropRepeatsWith, or R.dropRepeatsBy to compare a derived value.
The first one. Later equal neighbours are skipped, so in ['a', 'a', 'b'] the first 'a' is the one kept.
It accepts a string but returns an array of characters, so R.dropRepeats('aabbcc') is ['a', 'b', 'c']. Add .join('') to get the string 'abc' back.
No. R.dropRepeats was added in Ramda v0.14.0 and is stable. It is not deprecated, experimental, or non-standard.

Next: R.dropRepeatsBy()

Collapse consecutive items that share the same derived value.

R.dropRepeatsBy() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful