Skip to main content

Function: between()

between<T>(min, max): Predicate<T>

Defined in: predicate/comparison/index.ts:179

Creates a predicate that tests if a value is within a range (inclusive).

Type Parameters

T

T extends number | bigint

Parameters

min

T

The minimum value (inclusive)

max

T

The maximum value (inclusive)

Returns

Predicate<T>

A predicate that returns true if min <= value <= max

Example

import * as R from 'remeda'

const numbers = [1, 5, 10, 15, 20, 25]
R.filter(numbers, between(10, 20)) // => [10, 15, 20]

// Real-world: Filter products by price range
const products = [
{ name: 'Budget', price: 5 },
{ name: 'Standard', price: 15 },
{ name: 'Premium', price: 50 }
]
R.filter(products, (p) => between(10, 30)(p.price))
// => [{ name: 'Standard', price: 15 }]

See

  • gt - for greater than comparison
  • lt - for less than comparison