README.md (3116B)
1 <!-- 2 3 @license Apache-2.0 4 5 Copyright (c) 2018 The Stdlib Authors. 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 19 --> 20 21 # isBetweenArray 22 23 > Test if a value is an array-like object where every element is between two values. 24 25 <section class="usage"> 26 27 ## Usage 28 29 ```javascript 30 var isBetweenArray = require( '@stdlib/assert/is-between-array' ); 31 ``` 32 33 #### isBetweenArray( value, a, b\[, left, right] ) 34 35 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). 36 37 ```javascript 38 var arr = [ 3, 4, 5 ]; 39 40 var bool = isBetweenArray( arr, 3, 5 ); 41 // returns true 42 43 bool = isBetweenArray( arr, 4, 5 ); 44 // returns false 45 46 bool = isBetweenArray( arr, 3, 4 ); 47 // returns false 48 ``` 49 50 By default, the function assumes that `a` and `b` are inclusive. 51 52 ```javascript 53 var arr = [ 3, 4, 5 ]; 54 55 var bool = isBetweenArray( arr, 3, 5 ); 56 // returns true 57 58 bool = isBetweenArray( arr, 3, 5, 'closed', 'closed' ); 59 // returns true 60 ``` 61 62 To make `a` and/or `b` exclusive, set the respective arguments to `'open'`. 63 64 ```javascript 65 var arr = [ 3, 4, 5 ]; 66 67 var bool = isBetweenArray( arr, 3, 5, 'open', 'closed' ); 68 // returns false 69 70 bool = isBetweenArray( arr, 3, 5, 'closed', 'open' ); 71 // returns false 72 ``` 73 74 </section> 75 76 <!-- /.usage --> 77 78 <section class="notes"> 79 80 ## Notes 81 82 - If `a` and `b` are inclusive, the element-wise comparison is equivalent to 83 84 ```text 85 a <= v_i <= b 86 ``` 87 88 - If `a` is exclusive and `b` is inclusive, the element-wise comparison is equivalent to 89 90 ```text 91 a < v_i <= b 92 ``` 93 94 - If `a` is inclusive and `b` is exclusive, the element-wise comparison is equivalent to 95 96 ```text 97 a <= v_i < b 98 ``` 99 100 - If `a` and `b` are exclusive, the element-wise comparison is equivalent to 101 102 ```text 103 a < v_i < b 104 ``` 105 106 - If provided an empty array-like `object`, the function returns `false`. 107 108 ```javascript 109 var bool = isBetweenArray( [], 0.0, 1.0 ); 110 // returns false 111 ``` 112 113 - If provided non-numeric values, element-wise comparisons are performed according to lexicographic order. 114 115 </section> 116 117 <!-- /.notes --> 118 119 <section class="examples"> 120 121 ## Examples 122 123 <!-- eslint no-undef: "error" --> 124 125 ```javascript 126 var randu = require( '@stdlib/random/base/randu' ); 127 var Float64Array = require( '@stdlib/array/float64' ); 128 var isBetweenArray = require( '@stdlib/assert/is-between-array' ); 129 130 var x; 131 var i; 132 133 x = new Float64Array( 100 ); 134 for ( i = 0; i < x.length; i++ ) { 135 x[ i ] = randu(); 136 } 137 console.log( isBetweenArray( x, 0.01, 0.99 ) ); 138 ``` 139 140 </section> 141 142 <!-- /.examples --> 143 144 <section class="links"> 145 146 </section> 147 148 <!-- /.links -->