@sullux/fp-light-range
v0.0.1
Published
A lightweight functional library for functional composition and object composition.
Downloads
4
Readme
fp-light-range
npm i @sullux/fp-light-range
source
test
Creates an iterable of integers spanning the given range. This can be a good way to functionally implement next n items logic or repeat n times logic.
range
range(start: Number, end: Number): Iterable<Number>
Given a start less than end, iterates forward; otherwise, iterates backwards. All ranges are inclusive. The following tests illustrate the functionality.
const { range } = require('./range')
const { deepStrictEqual } = require('assert')
describe('range', () => {
it('should produce a low to high range', () => deepStrictEqual(
[...range(1, 3)],
[1, 2, 3]
))
it('should produce a high to low range', () => deepStrictEqual(
[...range(3, 1)],
[3, 2, 1]
))
it('should produce a single digit range', () => deepStrictEqual(
[...range(1, 1)],
[1]
))
})
...