📏Range

The Range class provides utility methods for working with numeric ranges.

pageRange
// Example 1: range with step
rangeTo(0,10,3)
    .forEach(it => console.log(`Index: ${it}`));
// Output:
//    Index: 0
//    Index: 3
//    Index: 6
//    Index: 9
// Example 2: Creating a Numeric Range
const numericRange = Range.rangeTo(1, 5, 2);
console.log(numericRange); 
// Output: [1, 3, 5]
// Example 3: Creating a Numeric Range (Exclusive)
const numericRangeAlias = rangeUntil(1, 5, 2);
console.log(numericRangeAlias); 
// Output: [1, 3, 5]
// Example 4: Checking if a Value is in Range
const isInRange = Range.inRange(3, 1, 5);
console.log(isInRange); 
// Output: true
// Example 5: Range with chaining Operations 
rangeTo(1, 5, 2)
    .runIt(function () {
        console.log(`multiplying the following range of numbers: ${this}`);
        this.map(it => it * 2)
            .forEach(it => console.log(it));
    });
// Output:
//    multiplying the following range of numbers: 1,3,5
//    2
//    6
//    10

Last updated