feat: add assert/is-ragged-nested-array#1368
Conversation
…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
stdlib-bot
left a comment
There was a problem hiding this comment.
👋 Hi there! 👋
And thank you for opening your first pull request! We will review it shortly. 🏃 💨
assert/is-ragged-nested-array
Pranavchiku
left a comment
There was a problem hiding this comment.
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
|
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>
| console.log( isRaggedNestedArray( [ [1, 2, 3], [4, 5] ] ) ); | ||
| // => true | ||
|
|
||
| console.log( isRaggedNestedArray( [ [1, 2, 3], [4, 5, 6] ] ) ); |
There was a problem hiding this comment.
| 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.
There was a problem hiding this comment.
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?
Signed-off-by: Athan <kgryte@gmail.com>
| 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 ) { |
There was a problem hiding this comment.
| 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", | |||
There was a problem hiding this comment.
The indentation in this file is off.
| "2d", | ||
| "two-dimensional" | ||
| ] | ||
| } No newline at end of file |
| "ragged", | ||
| "nested", | ||
| "is", | ||
| "israggednestedarray", |
There was a problem hiding this comment.
| "israggednestedarray", | |
| "isarray", |
| * limitations under the License. | ||
| */ | ||
|
|
||
| /* eslint-disable no-unused-vars */ |
There was a problem hiding this comment.
Test files should never have unused variables.
There was a problem hiding this comment.
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] ], |
| false, | ||
| {}, | ||
| function boop( a, b, c ) {}, | ||
| [1, 2, 3] |
There was a problem hiding this comment.
Add empty array and [ [ 1, 2, 3 ] ].
kgryte
left a comment
There was a problem hiding this comment.
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
…ttps://github.com/performant23/stdlib into feature/add-@stdlib/assert/is-ragged-nested-array
|
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. |
Planeshifter
left a comment
There was a problem hiding this comment.
Thanks for making the requested changes and your contribution, @performant23! This looks good to me; will merge shortly.
Add support for checking if array-like objects are ragged and nested.
Resolves #1347
Description
This pull request:
Related Issues
This pull request:
@stdlib/assert/is-ragged-nested-array#1347Questions
No.
Other
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
@stdlib-js/reviewers