Skip to content

Commit 0c57587

Browse files
Jaysukh-409kgryte
andauthored
feat: add boolean dtype support to array/base/every
PR-URL: #2423 Ref: #2304 Co-authored-by: Athan Reines <kgryte@gmail.com> Reviewed-by: Athan Reines <kgryte@gmail.com> Signed-off-by: Athan Reines <kgryte@gmail.com>
1 parent a480f85 commit 0c57587

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

lib/node_modules/@stdlib/array/base/every/lib/main.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@
2222

2323
var isComplex128Array = require( '@stdlib/array/base/assert/is-complex128array' );
2424
var isComplex64Array = require( '@stdlib/array/base/assert/is-complex64array' );
25+
var isBooleanArray = require( '@stdlib/array/base/assert/is-booleanarray' );
2526
var arraylike2object = require( '@stdlib/array/base/arraylike2object' );
2627
var reinterpret128 = require( '@stdlib/strided/base/reinterpret-complex128' );
2728
var reinterpret64 = require( '@stdlib/strided/base/reinterpret-complex64' );
29+
var reinterpretBoolean = require( '@stdlib/strided/base/reinterpret-boolean' );
2830

2931

3032
// FUNCTIONS //
@@ -165,6 +167,10 @@ function every( x ) {
165167
if ( isComplex64Array( x ) ) {
166168
return internalComplex( reinterpret64( x, 0 ) );
167169
}
170+
// If provided a boolean array, reinterpret as a typed array and test each element...
171+
if ( isBooleanArray( x ) ) {
172+
return internal( reinterpretBoolean( x, 0 ) );
173+
}
168174
return accessors( obj );
169175
}
170176
return internal( x );

lib/node_modules/@stdlib/array/base/every/test/test.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var AccessorArray = require( '@stdlib/array/base/accessor' );
2525
var Float64Array = require( '@stdlib/array/float64' );
2626
var Complex64Array = require( '@stdlib/array/complex64' );
2727
var Complex128Array = require( '@stdlib/array/complex128' );
28+
var BooleanArray = require( '@stdlib/array/bool' );
2829
var every = require( './../lib' );
2930

3031

@@ -74,6 +75,17 @@ tape( 'if provided an empty collection, the function returns `true` (complex typ
7475
t.end();
7576
});
7677

78+
tape( 'if provided an empty collection, the function returns `true` (boolean array)', function test( t ) {
79+
var out;
80+
var arr;
81+
82+
arr = new BooleanArray( [] );
83+
out = every( arr );
84+
85+
t.strictEqual( out, true, 'returns expected value' );
86+
t.end();
87+
});
88+
7789
tape( 'if provided an empty collection, the function returns `true` (accessor)', function test( t ) {
7890
var out;
7991
var arr;
@@ -107,7 +119,7 @@ tape( 'the function returns `true` if all elements are truthy (real typed array)
107119
t.end();
108120
});
109121

110-
tape( 'the function returns `true` if all elements are truthy (real typed array)', function test( t ) {
122+
tape( 'the function returns `true` if all elements are truthy (complex typed array)', function test( t ) {
111123
var out;
112124
var arr;
113125

@@ -123,6 +135,17 @@ tape( 'the function returns `true` if all elements are truthy (real typed array)
123135
t.end();
124136
});
125137

138+
tape( 'the function returns `true` if all elements are truthy (boolean array)', function test( t ) {
139+
var out;
140+
var arr;
141+
142+
arr = new BooleanArray( [ true, true, true, true ] );
143+
out = every( arr );
144+
145+
t.strictEqual( out, true, 'returns expected value' );
146+
t.end();
147+
});
148+
126149
tape( 'the function returns `true` if all elements are truthy (accessor)', function test( t ) {
127150
var out;
128151
var arr;
@@ -188,6 +211,17 @@ tape( 'the function returns `false` if one or more elements are falsy (complex t
188211
t.end();
189212
});
190213

214+
tape( 'the function returns `false` if one or more elements are falsy (boolean array)', function test( t ) {
215+
var out;
216+
var arr;
217+
218+
arr = new BooleanArray( [ true, false, false, true ] );
219+
out = every( arr );
220+
221+
t.strictEqual( out, false, 'returns expected value' );
222+
t.end();
223+
});
224+
191225
tape( 'the function returns `false` if one or more elements are falsy (accessor)', function test( t ) {
192226
var out;
193227
var arr;

0 commit comments

Comments
 (0)