isLesserEqual()
isLesserEqual<
T
>(threshold
): (value
) =>boolean
Creates a predicate function that determines if a value is less than or equal to a threshold.
Type Parameters
T
T
extends string
| number
The type of the values (number or string)
Parameters
threshold
T
The threshold value to compare against
Returns
(
value
):boolean
Parameters
value
T
Returns
boolean
Remarks
- Pure function with no side effects
- Uses JavaScript's
<=
operator for comparison - Works with both numbers and strings (lexicographic comparison for strings)
- Inclusive comparison (equal values return true)
- Useful for array filtering and functional composition
Example
const isAtMost100 = isLesserEqual(100);
isAtMost100(50); // true
isAtMost100(100); // true (inclusive)
isAtMost100(150); // false
const isAtMostM = isLesserEqual('M');
isAtMostM('A'); // true
isAtMostM('M'); // true
isAtMostM('Z'); // false
// Useful with arrays
const ages = [16, 18, 21, 25, 30];
const underAge = ages.filter(isLesserEqual(20)); // [16, 18]