Test if a value is an array-like object where every element is between two values.
npm install @stdlib/assert-is-between-arrayAlternatively,
- To load the package in a website via a
scripttag without installation and bundlers, use the ES Module available on theesmbranch. - If you are using Deno, visit the
denobranch. - For use in Observable, or in browser/node environments, use the Universal Module Definition (UMD) build available on the
umdbranch.
The branches.md file summarizes the available branches and displays a diagram illustrating their relationships.
var isBetweenArray = require( '@stdlib/assert-is-between-array' );Tests if a value is an array-like object where every element is between two values a (left comparison value) and b (right comparison value).
var arr = [ 3, 4, 5 ];
var bool = isBetweenArray( arr, 3, 5 );
// returns true
bool = isBetweenArray( arr, 4, 5 );
// returns false
bool = isBetweenArray( arr, 3, 4 );
// returns falseBy default, the function assumes that a and b are inclusive.
var arr = [ 3, 4, 5 ];
var bool = isBetweenArray( arr, 3, 5 );
// returns true
bool = isBetweenArray( arr, 3, 5, 'closed', 'closed' );
// returns trueTo make a and/or b exclusive, set the respective arguments to 'open'.
var arr = [ 3, 4, 5 ];
var bool = isBetweenArray( arr, 3, 5, 'open', 'closed' );
// returns false
bool = isBetweenArray( arr, 3, 5, 'closed', 'open' );
// returns false-
If
aandbare inclusive, the element-wise comparison is equivalent toa <= v_i <= b -
If
ais exclusive andbis inclusive, the element-wise comparison is equivalent toa < v_i <= b -
If
ais inclusive andbis exclusive, the element-wise comparison is equivalent toa <= v_i < b -
If
aandbare exclusive, the element-wise comparison is equivalent toa < v_i < b -
If provided an empty array-like
object, the function returnsfalse.var bool = isBetweenArray( [], 0.0, 1.0 ); // returns false
-
If provided non-numeric values, element-wise comparisons are performed according to lexicographic order.
var randu = require( '@stdlib/random-base-randu' );
var filledarrayBy = require( '@stdlib/array-filled-by' );
var isBetweenArray = require( '@stdlib/assert-is-between-array' );
// Create an array of random numbers:
var x = filledarrayBy( 100, 'float64', randu );
// Check whether every element resides within the interval [0.01, 0.99]:
var bool = isBetweenArray( x, 0.01, 0.99 );
console.log( bool );@stdlib/assert-is-between: test if a value is between two values.
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
See LICENSE.
Copyright © 2016-2023. The Stdlib Authors.