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

Conversation

performant23
Copy link
Contributor

Add support for checking if array-like objects are ragged and nested.

Resolves #1347

Description

What is the purpose of this pull request?

This pull request:

  • Adds support for checking if array-like objects are ragged and nested.

Related Issues

Does this pull request have any related issues?

This pull request:

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

The test results when applied on the functionality (benchmarks, examples, tests) can be found here - https://drive.google.com/drive/folders/1AomH4BL-sKkQCO6lhFU5BUelUW3wZp4f?usp=sharing

Checklist

Please ensure the following tasks are completed before submitting this pull request.


@stdlib-js/reviewers

…isRaggedNestedArray' (assert/is-ragged-nested-array)

Add support for checking if array-like objects are ragged and nested.

Fixes: stdlib-js#1347
Issue Link: stdlib-js#1347
Copy link
Contributor

@stdlib-bot stdlib-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋 Hi there! 👋

And thank you for opening your first pull request! We will review it shortly. 🏃 💨

@kgryte kgryte changed the title feat(@stdlib/assert): if applied, this commit will add the function isRaggedNestedArray' (assert/is-ragged-nested-array), Resolves #1347 feat: add assert/is-ragged-nested-array Feb 24, 2024
@kgryte kgryte added Feature Issue or pull request for adding a new feature. Needs Review A pull request which needs code review. Utilities Issue or pull request concerning general utilities. labels Feb 24, 2024
Copy link
Member

@Pranavchiku Pranavchiku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address following suggestion, also run the tests, benchmarks prior to pushing the changes.

…sRaggedNestedArray' (Revision 1)

Add support for checking if array-like objects are ragged and nested.
Signed-off-by: Pranavchiku goswami.4@iitj.ac.in
@performant23
Copy link
Contributor Author

Hello, I have modified the files, marked the suggestions as done, and pushed the commit with the changes! Please do let me know if there are any further changes necessary.

Signed-off-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
Comment on lines 25 to 28
console.log( isRaggedNestedArray( [ [1, 2, 3], [4, 5] ] ) );
// => true

console.log( isRaggedNestedArray( [ [1, 2, 3], [4, 5, 6] ] ) );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Here and elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion @kgryte! Just to confirm, you mean adding a leading and trailing whitespace in array initializations in all files in the package not just this one right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Signed-off-by: Athan <kgryte@gmail.com>
Comment on lines 47 to 59
var len = -1;
var i;

if ( !isArrayLikeObject( value ) ) {
return false;
}
for ( i = 0; i < value.length; i++ ) {
if ( !isArrayLikeObject( value[i] ) ) {
return false;
}
if ( len === -1 ) {
len = value[i].length;
} else if ( value[i].length !== len ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var len = -1;
var i;
if ( !isArrayLikeObject( value ) ) {
return false;
}
for ( i = 0; i < value.length; i++ ) {
if ( !isArrayLikeObject( value[i] ) ) {
return false;
}
if ( len === -1 ) {
len = value[i].length;
} else if ( value[i].length !== len ) {
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 ) {

Empty and single element arrays are not ragged. You can avoid additional branching logic by caching the length of the first array.

@@ -0,0 +1,75 @@
{
"name": "@stdlib/assert/is-ragged-nested-array",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation in this file is off.

"2d",
"two-dimensional"
]
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing newline.

"ragged",
"nested",
"is",
"israggednestedarray",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"israggednestedarray",
"isarray",

* limitations under the License.
*/

/* eslint-disable no-unused-vars */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test files should never have unused variables.

Copy link
Contributor Author

@performant23 performant23 Feb 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct, thanks! Also, just noticed that the package 'is-array-like-object', had this line in the test.js file.
/* eslint-disable object-curly-newline, no-unused-vars */
I'm not sure if it's the expected behavior there, but in case it isn't, just letting you know!

Edit: So, just noticed that this is used 20 times in 9 files in node_modules/@StdLib

var i;

values = [
[ [1, 2, 3], [4, 5] ],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spacing.

false,
{},
function boop( a, b, c ) {},
[1, 2, 3]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add empty array and [ [ 1, 2, 3 ] ].

Copy link
Member

@kgryte kgryte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this, @performant23. This is shaping up. So long as the comments are addressed, this is on track for being merged.

…sRaggedNestedArray' (Revision 2)

Add support for checking if array-like objects are ragged and nested.
Signed-off-by: Athan kgryte@gmail.com
@performant23
Copy link
Contributor Author

Hey everyone, I have modified the files and pushed the commit with the changes! Please do let me know if there are any further changes necessary.

Copy link
Member

@Planeshifter Planeshifter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making the requested changes and your contribution, @performant23! This looks good to me; will merge shortly.

@Planeshifter Planeshifter merged commit 0fb4869 into stdlib-js:develop Feb 26, 2024
@Planeshifter Planeshifter removed the Needs Review A pull request which needs code review. label Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Issue or pull request for adding a new feature. Utilities Issue or pull request concerning general utilities.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RFC]: add @stdlib/assert/is-ragged-nested-array
5 participants