Range function (returns array of values in range).
Both es6 modules and common-js modules supported by default.
import {range} from 'fjl-range';
const testRange = [-3, -4, -5, 1, 2, 3, 99, 98, 97];
range(-3, -5, -1).concat(range(1, 3), range(99, 97, -1))
.every((x, ind) => x === testRange[ind]) === true // true
or
const {range} = require('fjl-range');
// ...
or use one of 'amd', 'umd', 'iife', or 'commonjs' builds included in './dist' folder: Example:
<!-- If imported globally ('iife') exported as `fjlRange` globally -->
<script src="js/vendor/fjl-range/dist/iife/fjl-range.js"></script>
Same as above or look/include files directly from './dist' folder for your module loading type (amd, umd, iife, commonjs, and/or module).
Returns an array of numbers generated from the given 'range' (from
-> to
) and step
values:
// Positve direction range
shallowCompare(range(1, 5), [1, 2, 3, 4, 5]) === true // true
shallowCompare(range(1, 5, 1), [1, 2, 3, 4, 5]) === true // true
// Negative numbers range
shallowCompare(range(-5, -1, 1), [-5, -4, -3, -2, -1]) === true // true
// Negative direction
shallowCompare(range(-3, -5, -1), [-3, -4, -5]) === true // true
// Auto normalize step for given range
shallowCompare(range$(-3, -5), [-3, -4, -5]) === true // true
// Note here that we are not passing a `step` and that the default `step` is `1`
// hence our step is invalid though this version of `range` normalizes
// the step for us if it is invalid. Also note that we are using `range$` here
// instead of `range` (for this functionality)
Haskell type: range :: Number a => a -> a -> a -> [a]
Same as range
except normalizes step
variable to be valid; E.g.,
range$(-3, -5) // Still produces a valid range despite the default `step` being `1`
// This version of range looks at the `from` and `to` variables
// and checks if `from` is greater than `to` and if so return a negative version of step
// else does the opposite.
npm install
- Look at node scripts in package.json.
-
npm test
(afternpm install
).
JsDocs here: https://functional-jslib.github.io/fjl-range
GNU v2, v3