Ramda.js R.aperture() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
List

Definition

R.aperture(n, list) slides a window of size n across the list and returns every position as a small array (official Ramda docs). Neighboring windows overlap by n - 1 items, which makes it ideal for the sliding window pattern: comparing neighbors, moving averages, and pairs.

Stable since v0.12.0: R.aperture is not deprecated, experimental, or non-standard. JavaScript has no built-in array method that does the same job.

Syntax

Call R.aperture. Start with this line.

Ramda
R.aperture(n, list) or R.aperture(n)(list)
CallWhat it does
R.aperture(n, list) or R.aperture(n)(list)Primary signature.
R.aperture(...)Call the list helper.

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

Library declarations
Ramda
R.aperture(n, list) or R.aperture(n)(list)

Parameters

ParameterDescription
nRequired. Window size — a whole number of at least 1
listRequired. Array (or array-like) to slide over — never changed

Return Value

Return ValueDescription
*A new array of length - n + 1 windows, or []

Ramda Examples

Example 1 — Official Pairs, Triples, and Too-Big n

The three samples from the Ramda docs on the same five-item list.

Ramda
const nums = [1, 2, 3, 4, 5];

console.log(R.aperture(2, nums)); // [[1, 2], [2, 3], [3, 4], [4, 5]]
console.log(R.aperture(3, nums)); // [[1, 2, 3], [2, 3, 4], [3, 4, 5]]
console.log(R.aperture(7, nums)); // []
Try It Yourself

How It Works

  1. Pairs. A window of 2 starts at index 0 and moves one step at a time: 5 - 2 + 1 = 4 windows.
  2. Overlap. Each window shares one item with the next — 2 is in both [1, 2] and [2, 3].
  3. Triples. A window of 3 fits 5 - 3 + 1 = 3 times.
  4. Too big. A window of 7 cannot fit in 5 items, so the result is [].

Example 2 — Change Between Neighbors

How much did the temperature change from one day to the next?

Ramda
const temps = [18, 21, 19, 24];

const changes = R.map(([a, b]) => b - a, R.aperture(2, temps));

console.log(changes); // [3, -2, 5]
Try It Yourself

How It Works

  1. Make pairs. R.aperture(2, temps) → [[18, 21], [21, 19], [19, 24]].
  2. Unpack. Array destructuring ([a, b]) names the two days in each pair.
  3. Subtract. b - a gives the change: 21 - 18 = 3, 19 - 21 = -2, 24 - 19 = 5.
  4. One shorter. Four readings give three changes — there is always one fewer pair than items.

Example 3 — Moving Average of Three

Smooth a series by averaging each run of three values.

Ramda
const sales = [10, 20, 30, 40, 50];

const averages = R.map(R.mean, R.aperture(3, sales));

console.log(averages); // [20, 30, 40]
Try It Yourself

How It Works

  1. Make triples. R.aperture(3, sales) → [[10, 20, 30], [20, 30, 40], [30, 40, 50]].
  2. Average each. R.mean takes an array and returns its average.
  3. Map. R.map(R.mean, ...) turns each triple into one number: 20, 30, 40.
  4. Size. A 3-wide window over 5 values gives 5 - 3 + 1 = 3 averages.

Example 4 — Is the List Sorted?

Check every neighbor pair with R.all inside a pipeline.

Ramda
const isSorted = R.pipe(
  R.aperture(2),
  R.all(([a, b]) => a <= b)
);

console.log(isSorted([1, 2, 2, 5])); // true
console.log(isSorted([1, 3, 2]));    // false
console.log(isSorted([]));           // true
Try It Yourself

How It Works

  1. Curry. R.aperture(2) waits for a list, so it can be the first step of R.pipe.
  2. Check pairs. R.all tests a <= b on every neighbor pair.
  3. Catch a drop. In [1, 3, 2] the pair [3, 2] fails, so the answer is false.
  4. Empty list. [] has no pairs, and R.all on [] is true — an empty list counts as sorted.

Example 5 — aperture vs splitEvery

Same list, same size: overlapping windows versus separate chunks.

Ramda
const nums = [1, 2, 3, 4, 5];

console.log(R.aperture(2, nums));   // [[1, 2], [2, 3], [3, 4], [4, 5]]
console.log(R.splitEvery(2, nums)); // [[1, 2], [3, 4], [5]]
Try It Yourself

How It Works

  1. Slide. R.aperture moves one step at a time, so items are reused across windows.
  2. Chop. R.splitEvery moves n steps at a time, so each item appears once.
  3. Leftovers. splitEvery keeps the short last chunk [5]; aperture never makes a short window.
  4. Pick by need. Comparing neighbors → aperture. Paging or batching → splitEvery.

Browser & Runtime Support

R.aperture() is plain JavaScript inside Ramda (available since v0.12.0). It uses no browser API, so support depends only on loading Ramda.

✓ Ramda 0.12.0+ · Any JS runtime

Ramda.js R.aperture()

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. The arrow functions and array destructuring in some examples need an ES2015+ engine, which every modern browser has.

100% With Ramda loaded
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.aperture() Universal

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

Frequently Asked Questions

R.aperture(n, list) returns a new list of overlapping windows, each holding n consecutive items. Official sample: R.aperture(2, [1, 2, 3, 4, 5]) returns [[1, 2], [2, 3], [3, 4], [4, 5]].
list.length - n + 1 windows when n fits in the list. Five items with n = 2 give 4 windows; with n = 3 they give 3 windows. If n is larger than the list, the result is an empty array.
R.aperture returns an empty array, with no error. The official sample R.aperture(7, [1, 2, 3, 4, 5]) returns [].
R.aperture slides one step at a time, so windows overlap and share items. R.splitEvery cuts the list into separate chunks that never overlap. On [1, 2, 3, 4, 5] with 2: aperture gives [[1, 2], [2, 3], [3, 4], [4, 5]], while splitEvery gives [[1, 2], [3, 4], [5]].
Anything that compares neighbors or looks at a moving range: differences between consecutive values, moving averages, checking whether a list is sorted, or building word pairs (bigrams).
No. R.aperture has been a stable Ramda list function since v0.12.0. It is not deprecated, experimental, or non-standard.

Next: R.append()

Add one item to the end of a list without changing the original.

R.append() 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