From 9286669efb4016bfd990d44bfcf13ee806800219 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 26 Feb 2024 15:39:35 +0000 Subject: [PATCH] Auto-generated commit --- .npmignore | 3 +- CONTRIBUTORS | 3 + is-ragged-nested-array/README.md | 106 ++++++++++++++++++ is-ragged-nested-array/benchmark/benchmark.js | 89 +++++++++++++++ is-ragged-nested-array/docs/repl.txt | 26 +++++ is-ragged-nested-array/docs/types/index.d.ts | 44 ++++++++ is-ragged-nested-array/docs/types/test.ts | 35 ++++++ is-ragged-nested-array/examples/index.js | 50 +++++++++ is-ragged-nested-array/lib/index.js | 46 ++++++++ is-ragged-nested-array/lib/main.js | 67 +++++++++++ is-ragged-nested-array/package.json | 75 +++++++++++++ is-ragged-nested-array/test/test.js | 89 +++++++++++++++ 12 files changed, 632 insertions(+), 1 deletion(-) create mode 100644 is-ragged-nested-array/README.md create mode 100644 is-ragged-nested-array/benchmark/benchmark.js create mode 100644 is-ragged-nested-array/docs/repl.txt create mode 100644 is-ragged-nested-array/docs/types/index.d.ts create mode 100644 is-ragged-nested-array/docs/types/test.ts create mode 100644 is-ragged-nested-array/examples/index.js create mode 100644 is-ragged-nested-array/lib/index.js create mode 100644 is-ragged-nested-array/lib/main.js create mode 100644 is-ragged-nested-array/package.json create mode 100644 is-ragged-nested-array/test/test.js diff --git a/.npmignore b/.npmignore index 5c7f09d7..8eea7dc2 100644 --- a/.npmignore +++ b/.npmignore @@ -29,8 +29,9 @@ branches.md .postinstall.json Makefile -# Ignore `binding.gyp` file to avoid compilation of native addon when installing package: +# Ignore files to avoid compilation of native addon when installing package: binding.gyp +include.gypi # Directories # ############### diff --git a/CONTRIBUTORS b/CONTRIBUTORS index a0849169..26c41fe0 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -15,6 +15,7 @@ Dominik Moritz Dorrin Sotoudeh Frank Kovacs GUNJ JOSHI +Golden <103646877+AuenKr@users.noreply.github.com> Harshita Kalani James Gelok Jaysukh Makvana @@ -24,6 +25,7 @@ Jordan Gallivan <115050475+Jordan-Gallivan@users.noreply.github.com> Joris Labie Justin Dennison Karthik Prakash <116057817+skoriop@users.noreply.github.com> +Khaldon Marcus Fantham Matt Cochrane Milan Raj @@ -32,6 +34,7 @@ Naresh Jagadeesan Nithin Katta <88046362+nithinkatta@users.noreply.github.com> Ognjen Jevremović Philipp Burckhardt +Prajwal Kulkarni Pranav Goswami Ricky Reusser Robert Gislason diff --git a/is-ragged-nested-array/README.md b/is-ragged-nested-array/README.md new file mode 100644 index 00000000..2889b561 --- /dev/null +++ b/is-ragged-nested-array/README.md @@ -0,0 +1,106 @@ + + +# isRaggedNestedArray + +> Test if a value is a ragged nested array. + +
+ +## 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 +``` + +
+ + + +
+ +## Examples + + + + + +```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 +``` + +
+ + + + + + + + + + + + + + diff --git a/is-ragged-nested-array/benchmark/benchmark.js b/is-ragged-nested-array/benchmark/benchmark.js new file mode 100644 index 00000000..b8392bd5 --- /dev/null +++ b/is-ragged-nested-array/benchmark/benchmark.js @@ -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(); +}); diff --git a/is-ragged-nested-array/docs/repl.txt b/is-ragged-nested-array/docs/repl.txt new file mode 100644 index 00000000..796e16b8 --- /dev/null +++ b/is-ragged-nested-array/docs/repl.txt @@ -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 + -------- + diff --git a/is-ragged-nested-array/docs/types/index.d.ts b/is-ragged-nested-array/docs/types/index.d.ts new file mode 100644 index 00000000..6ffe4211 --- /dev/null +++ b/is-ragged-nested-array/docs/types/index.d.ts @@ -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; diff --git a/is-ragged-nested-array/docs/types/test.ts b/is-ragged-nested-array/docs/types/test.ts new file mode 100644 index 00000000..cfb2df8d --- /dev/null +++ b/is-ragged-nested-array/docs/types/test.ts @@ -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 +} diff --git a/is-ragged-nested-array/examples/index.js b/is-ragged-nested-array/examples/index.js new file mode 100644 index 00000000..3fdb3440 --- /dev/null +++ b/is-ragged-nested-array/examples/index.js @@ -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 diff --git a/is-ragged-nested-array/lib/index.js b/is-ragged-nested-array/lib/index.js new file mode 100644 index 00000000..df7394f1 --- /dev/null +++ b/is-ragged-nested-array/lib/index.js @@ -0,0 +1,46 @@ +/** +* @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'; + +/** +* Test if a value is a ragged nested array. +* +* @module @stdlib/assert/is-ragged-nested-array +* +* @example +* 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 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/is-ragged-nested-array/lib/main.js b/is-ragged-nested-array/lib/main.js new file mode 100644 index 00000000..185ee83f --- /dev/null +++ b/is-ragged-nested-array/lib/main.js @@ -0,0 +1,67 @@ +/** +* @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 isArrayLikeObject = require( './../../is-array-like-object' ); + + +// MAIN // + +/** +* Tests if a value is a ragged nested array. +* +* @param {*} value - value to test +* @returns {boolean} 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 +*/ +function isRaggedNestedArray( value ) { + var len; + var i; + if ( !isArrayLikeObject( value ) || value.length < 2 ) { + return false; + } + len = value[ 0 ].length; + for ( i = 1; i < value.length; i++ ) { + if ( !isArrayLikeObject( value[ i ] ) ) { + return false; + } + if ( value[ i ].length !== len ) { + return true; + } + } + return false; +} + + +// EXPORTS // + +module.exports = isRaggedNestedArray; diff --git a/is-ragged-nested-array/package.json b/is-ragged-nested-array/package.json new file mode 100644 index 00000000..fc88beed --- /dev/null +++ b/is-ragged-nested-array/package.json @@ -0,0 +1,75 @@ +{ + "name": "@stdlib/assert/is-ragged-nested-array", + "version": "0.0.0", + "description": "Test if a value is a ragged nested array", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdassert", + "assertion", + "assert", + "utilities", + "utility", + "utils", + "util", + "array", + "ragged", + "nested", + "is", + "isarray", + "object", + "obj", + "type", + "check", + "test", + "validate", + "isvalid", + "2d", + "two-dimensional" + ] +} diff --git a/is-ragged-nested-array/test/test.js b/is-ragged-nested-array/test/test.js new file mode 100644 index 00000000..3ac89237 --- /dev/null +++ b/is-ragged-nested-array/test/test.js @@ -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 tape = require( 'tape' ); +var isRaggedNestedArray = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof isRaggedNestedArray, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns `true` if provided a ragged nested array', function test( t ) { + var values; + var i; + + values = [ + [ [ 1, 2, 3 ], [ 4, 5 ] ], + [ [ 1, 2, 3 ], [ 4, 5, 6, 7 ] ], + [ [ 1 ], [ 2, 3 ], [ 4, 5, 6 ] ] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.strictEqual( isRaggedNestedArray(values[ i ]), true, 'returns true when provided ' + values[ i ] ); + } + t.end(); +}); + +tape( 'the function returns `false` if provided a non-ragged nested array', function test( t ) { + var values; + var i; + + values = [ + [ [ 1, 2, 3 ], [ 4, 5, 6 ] ], + [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.strictEqual( isRaggedNestedArray(values[ i ]), false, 'returns false when provided ' + values[ i ] ); + } + t.end(); +}); + +tape( 'the function returns `false` if not provided a nested array', function test( t ) { + var values; + var i; + + values = [ + 'beep', + 5, + null, + void 0, + NaN, + true, + false, + {}, + [], + [ [ 1, 2, 3 ] ], + function noop() {}, + [ 1, 2, 3 ] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.strictEqual( isRaggedNestedArray( values[ i ] ), false, 'returns false when provided ' + values[ i ] ); + } + t.end(); +});