Skip to content

feat: add assert/is-ragged-nested-array #1368

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 106 additions & 0 deletions lib/node_modules/@stdlib/assert/is-ragged-nested-array/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<!--

@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.

-->

# isRaggedNestedArray

> Test if a value is a ragged nested array.

<section class="usage">

## Usage

```javascript
var isRaggedNestedArray = require( '@stdlib/assert/is-ragged-nested-array' );
```

#### isRaggedNestedArray( value )

Tests if a value is a ragged nested array.

```javascript
var bool = isRaggedNestedArray( [ [ 1, 2, 3 ], [ 4, 5 ] ] );
// returns true

bool = isRaggedNestedArray( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] );
// returns false
```

</section>

<!-- /.usage -->

<section class="examples">

## Examples

<!-- eslint-disable no-empty-function, no-restricted-syntax -->

<!-- eslint no-undef: "error" -->

```javascript
var isRaggedNestedArray = require( '@stdlib/assert/is-ragged-nested-array' );

var bool = isRaggedNestedArray( [ [ 1, 2, 3 ], [ 4, 5 ] ] );
// returns true

bool = isRaggedNestedArray( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] );
// returns false

bool = isRaggedNestedArray( 'beep' );
// returns false

bool = isRaggedNestedArray( null );
// returns false

bool = isRaggedNestedArray( void 0 );
// returns false

bool = isRaggedNestedArray( 5 );
// returns false

bool = isRaggedNestedArray( true );
// returns false

bool = isRaggedNestedArray( {} );
// returns false

bool = isRaggedNestedArray( function noop() {} );
// returns false
```

</section>

<!-- /.examples -->

<!-- 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 -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/**
* @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 pkg = require( './../package.json' ).name;
var isRaggedNestedArray = require( './../lib' );


// MAIN //

bench( pkg+'::ragged_array', function benchmark( b ) {
var bool;
var arr;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
arr = [ [ i, i+1, i+2 ], [ i-1, i-2 ] ];
bool = isRaggedNestedArray( arr );
if ( typeof bool !== 'boolean' ) {
b.fail( 'should return a boolean' );
}
}
b.toc();
if ( !bool ) {
b.fail( 'should return true' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( pkg+'::non_ragged_array', function benchmark( b ) {
var bool;
var arr;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
arr = [ [ i, i+1], [i-1, i ] ];
bool = isRaggedNestedArray( arr );
if ( typeof bool !== 'boolean' ) {
b.fail( 'should return a boolean' );
}
}
b.toc();
if ( bool ) {
b.fail( 'should return false' );
}
b.pass( 'benchmark finished' );
b.end();
});

bench( pkg+'::non_array', function benchmark( b ) {
var bool;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
bool = isRaggedNestedArray( i );
if ( typeof bool !== 'boolean' ) {
b.fail( 'should return a boolean' );
}
}
b.toc();
if ( bool ) {
b.fail( 'should return false' );
}
b.pass( 'benchmark finished' );
b.end();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

{{alias}}( value )
Tests if a value is a ragged nested array.

Parameters
----------
value: any
Value to test.

Returns
-------
bool: boolean
Boolean indicating whether a value is a ragged nested array.

Examples
--------
> var bool = {{alias}}( [ [ 1, 2, 3 ], [ 4, 5 ] ] )
true
> bool = {{alias}}( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] )
false
> bool = {{alias}}( 'beep' )
false

See Also
--------

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* @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

/**
* Tests if a value is a ragged nested array.
*
* @param value - value to test
* @returns boolean indicating if a value is a ragged nested array
*
* @example
* var bool = isRaggedNestedArray( [ [ 1, 2, 3 ], [ 4, 5 ] ] );
* // returns true
*
* @example
* var bool = isRaggedNestedArray( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] );
* // returns false
*
* @example
* var bool = isRaggedNestedArray( 'beep' );
* // returns false
*/
declare function isRaggedNestedArray( value: any ): boolean;


// EXPORTS //

export = isRaggedNestedArray;
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* @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 isRaggedNestedArray = require( './index' );


// TESTS //

// The function returns a boolean...
{
isRaggedNestedArray( [ [ 1, 2, 3 ], [ 4, 5 ] ] ); // $ExpectType boolean
isRaggedNestedArray( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ); // $ExpectType boolean
isRaggedNestedArray( 'beep' ); // $ExpectType boolean
}

// The compiler throws an error if the function is provided an unsupported number of arguments...
{
isRaggedNestedArray(); // $ExpectError
isRaggedNestedArray( [], 123 ); // $ExpectError
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* @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.
*/

/* eslint-disable no-empty-function, no-restricted-syntax */

'use strict';

var isRaggedNestedArray = require( './../lib' );

console.log( isRaggedNestedArray( [ [ 1, 2, 3 ], [ 4, 5 ] ] ) );
// => true

console.log( isRaggedNestedArray( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ) );
// => false

console.log( isRaggedNestedArray( 'beep' ) );
// => false

console.log( isRaggedNestedArray( null ) );
// => false

console.log( isRaggedNestedArray( void 0 ) );
// => false

console.log( isRaggedNestedArray( 5 ) );
// => false

console.log( isRaggedNestedArray( true ) );
// => false

console.log( isRaggedNestedArray( {} ) );
// => false

console.log( isRaggedNestedArray( function noop() {} ) );
// => false
Loading