-
-
Notifications
You must be signed in to change notification settings - Fork 836
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
Planeshifter
merged 16 commits into
stdlib-js:develop
from
performant23:feature/add-@stdlib/assert/is-ragged-nested-array
Feb 26, 2024
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
d1d40de
feat(@stdlib/assert): if applied, this commit will add the function '…
performant23 930e28e
feat(@stdlib/assert): if applied, this commit will add the function i…
performant23 c9b8af1
Apply suggestions from code review
kgryte 11eaa51
Apply suggestions from code review
kgryte 6b565ac
Apply suggestions from code review
kgryte 547a90e
Apply suggestions from code review
kgryte 4469ea1
Apply suggestions from code review
kgryte 39b883f
Apply suggestions from code review
kgryte 754ca0a
Apply suggestions from code review
kgryte 7a4e95b
Apply suggestions from code review
kgryte 6665a62
Apply suggestions from code review
kgryte c867372
Apply suggestions from code review
kgryte fdc1f4c
Apply suggestions from code review
kgryte 2bebaf4
Apply suggestions from code review
kgryte 39586ed
feat(@stdlib/assert): if applied, this commit will add the function i…
performant23 9f94915
Merge branch 'feature/add-@stdlib/assert/is-ragged-nested-array' of h…
performant23 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
106 changes: 106 additions & 0 deletions
106
lib/node_modules/@stdlib/assert/is-ragged-nested-array/README.md
This file contains hidden or 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,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 --> |
89 changes: 89 additions & 0 deletions
89
lib/node_modules/@stdlib/assert/is-ragged-nested-array/benchmark/benchmark.js
This file contains hidden or 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,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(); | ||
}); |
26 changes: 26 additions & 0 deletions
26
lib/node_modules/@stdlib/assert/is-ragged-nested-array/docs/repl.txt
This file contains hidden or 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,26 @@ | ||
|
||
{{alias}}( value ) | ||
performant23 marked this conversation as resolved.
Show resolved
Hide resolved
kgryte marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 | ||
-------- | ||
kgryte marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
44 changes: 44 additions & 0 deletions
44
lib/node_modules/@stdlib/assert/is-ragged-nested-array/docs/types/index.d.ts
This file contains hidden or 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,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; |
35 changes: 35 additions & 0 deletions
35
lib/node_modules/@stdlib/assert/is-ragged-nested-array/docs/types/test.ts
This file contains hidden or 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,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 // | ||
kgryte marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// 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 | ||
} |
50 changes: 50 additions & 0 deletions
50
lib/node_modules/@stdlib/assert/is-ragged-nested-array/examples/index.js
This file contains hidden or 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,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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.