-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f1cf3f1
commit 94d7654
Showing
13 changed files
with
909 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<!-- | ||
@license Apache-2.0 | ||
Copyright (c) 2024 The Stdlib Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
|
||
# none | ||
|
||
> Test whether all elements in an array are falsy. | ||
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> | ||
|
||
<section class="intro"> | ||
|
||
</section> | ||
|
||
<!-- /.intro --> | ||
|
||
<!-- Package usage documentation. --> | ||
|
||
<section class="usage"> | ||
|
||
## Usage | ||
|
||
```javascript | ||
var none = require( '@stdlib/array/base/none' ); | ||
``` | ||
|
||
#### none( x ) | ||
|
||
Tests whether all elements in an array are falsy. | ||
|
||
```javascript | ||
var x = [ 0, 0, 0, 0 ]; | ||
|
||
var bool = none( x ); | ||
// returns true | ||
``` | ||
|
||
</section> | ||
|
||
<!-- /.usage --> | ||
|
||
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||
|
||
<section class="notes"> | ||
|
||
## Notes | ||
|
||
- If provided an empty array, the function returns `true`. | ||
- The function does **not** skip `undefined` elements and is thus not optimized for sparse arrays. | ||
|
||
</section> | ||
|
||
<!-- /.notes --> | ||
|
||
<!-- Package usage examples. --> | ||
|
||
<section class="examples"> | ||
|
||
## Examples | ||
|
||
<!-- eslint no-undef: "error" --> | ||
|
||
```javascript | ||
var bernoulli = require( '@stdlib/random/array/bernoulli' ); | ||
var none = require( '@stdlib/array/base/none' ); | ||
|
||
var x = bernoulli( 10, 0.1, { | ||
'dtype': 'int8' | ||
} ); | ||
// returns <Int8Array> | ||
|
||
var out = none( x ); | ||
// returns <boolean> | ||
``` | ||
|
||
</section> | ||
|
||
<!-- /.examples --> | ||
|
||
<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||
|
||
<section class="references"> | ||
|
||
</section> | ||
|
||
<!-- /.references --> | ||
|
||
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> | ||
|
||
<section class="related"> | ||
|
||
</section> | ||
|
||
<!-- /.related --> | ||
|
||
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||
|
||
<section class="links"> | ||
|
||
</section> | ||
|
||
<!-- /.links --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/** | ||
* @license Apache-2.0 | ||
* | ||
* Copyright (c) 2024 The Stdlib Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
// MODULES // | ||
|
||
var bench = require( '@stdlib/bench' ); | ||
var pow = require( '@stdlib/math/base/special/pow' ); | ||
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; | ||
var zeros = require( './../../../base/zeros' ); | ||
var pkg = require( './../package.json' ).name; | ||
var none = require( './../lib' ); | ||
|
||
|
||
// FUNCTIONS // | ||
|
||
/** | ||
* Creates a benchmark function. | ||
* | ||
* @private | ||
* @param {PositiveInteger} len - array length | ||
* @returns {Function} benchmark function | ||
*/ | ||
function createBenchmark( len ) { | ||
var x = zeros( len ); | ||
return benchmark; | ||
|
||
/** | ||
* Benchmark function. | ||
* | ||
* @private | ||
* @param {Benchmark} b - benchmark instance | ||
*/ | ||
function benchmark( b ) { | ||
var out; | ||
var i; | ||
|
||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
out = none( x ); | ||
if ( typeof out !== 'boolean' ) { | ||
b.fail( 'should return a boolean' ); | ||
} | ||
} | ||
b.toc(); | ||
if ( !isBoolean( out ) ) { | ||
b.fail( 'should return a boolean' ); | ||
} | ||
b.pass( 'benchmark finished' ); | ||
b.end(); | ||
} | ||
} | ||
|
||
|
||
// MAIN // | ||
|
||
/** | ||
* Main execution sequence. | ||
* | ||
* @private | ||
*/ | ||
function main() { | ||
var len; | ||
var min; | ||
var max; | ||
var f; | ||
var i; | ||
|
||
min = 1; // 10^min | ||
max = 6; // 10^max | ||
|
||
for ( i = min; i <= max; i++ ) { | ||
len = pow( 10, i ); | ||
|
||
f = createBenchmark( len ); | ||
bench( pkg+':dtype=generic,len='+len, f ); | ||
} | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
{{alias}}( x ) | ||
Tests whether all elements in an array are falsy. | ||
|
||
The function returns immediately upon encountering a truthy value. | ||
|
||
If provided an empty array, the function returns `true`. | ||
|
||
Parameters | ||
---------- | ||
x: Array|TypedArray|Object | ||
Input array. | ||
|
||
Returns | ||
------- | ||
bool: boolean | ||
The function returns `true` if all elements are falsy; otherwise, the | ||
function returns `false`. | ||
|
||
Examples | ||
-------- | ||
> var x = [ 0, 0, 0, 0 ]; | ||
> var out = {{alias}}( x ) | ||
true | ||
|
||
See Also | ||
-------- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* @license Apache-2.0 | ||
* | ||
* Copyright (c) 2024 The Stdlib Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
// TypeScript Version: 4.1 | ||
|
||
/// <reference types="@stdlib/types"/> | ||
|
||
import { Collection, AccessorArrayLike } from '@stdlib/types/array'; | ||
|
||
/** | ||
* Tests whether all elements in an array are falsy. | ||
* | ||
* ## Notes | ||
* | ||
* - The function immediately returns upon encountering a truthy value. | ||
* - If provided an empty collection, the function returns `true`. | ||
* | ||
* @param x - input array | ||
* @returns boolean indicating whether all elements are falsy | ||
* | ||
* @example | ||
* var x = [ 0, 0, 0, 0 ]; | ||
* | ||
* var out = none( x ); | ||
* // returns true | ||
*/ | ||
declare function none<T = unknown>( x: Collection<T> | AccessorArrayLike<T> ): boolean; | ||
|
||
|
||
// EXPORTS // | ||
|
||
export = none; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* @license Apache-2.0 | ||
* | ||
* Copyright (c) 2024 The Stdlib Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import toAccessorArray = require( './../../../../base/to-accessor-array' ); | ||
import none = require( './index' ); | ||
|
||
|
||
// TESTS // | ||
|
||
// The function returns a boolean... | ||
{ | ||
none( [ 1, 2, 3 ] ); // $ExpectType boolean | ||
none( new Float64Array( [ 1, 2, 3 ] ) ); // $ExpectType boolean | ||
none( new Float32Array( [ 1, 2, 3 ] ) ); // $ExpectType boolean | ||
none( new Int32Array( [ 1, 2, 3 ] ) ); // $ExpectType boolean | ||
none( new Int16Array( [ 1, 2, 3 ] ) ); // $ExpectType boolean | ||
none( new Int8Array( [ 1, 2, 3 ] ) ); // $ExpectType boolean | ||
none( new Uint32Array( [ 1, 2, 3 ] ) ); // $ExpectType boolean | ||
none( new Uint16Array( [ 1, 2, 3 ] ) ); // $ExpectType boolean | ||
none( new Uint8Array( [ 1, 2, 3 ] ) ); // $ExpectType boolean | ||
none( new Uint8ClampedArray( [ 1, 2, 3 ] ) ); // $ExpectType boolean | ||
none( toAccessorArray( [ 1, 2, 3 ] ) ); // $ExpectType boolean | ||
} | ||
|
||
// The compiler throws an error if the function is provided a first argument which is not a collection... | ||
{ | ||
none( 2 ); // $ExpectError | ||
none( false ); // $ExpectError | ||
none( true ); // $ExpectError | ||
none( {} ); // $ExpectError | ||
} | ||
|
||
// The compiler throws an error if the function is provided an unsupported number of arguments... | ||
{ | ||
none(); // $ExpectError | ||
none( [ 1, 2, 3 ], {}, 3 ); // $ExpectError | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* @license Apache-2.0 | ||
* | ||
* Copyright (c) 2024 The Stdlib Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var bernoulli = require( '@stdlib/random/array/bernoulli' ); | ||
var none = require( './../lib' ); | ||
|
||
var x = bernoulli( 10, 0.1, { | ||
'dtype': 'int8' | ||
} ); | ||
// returns <Int8Array> | ||
|
||
var out = none( x ); | ||
// returns <boolean> | ||
|
||
console.log( x ); | ||
console.log( out ); |
Oops, something went wrong.