Skip to content

feat: add array/base/join #1463

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
merged 12 commits into from
Mar 5, 2024
Merged

Conversation

adityacodes30
Copy link
Contributor

@adityacodes30 adityacodes30 commented Mar 3, 2024

Resolves #1327 .

Description

What is the purpose of this pull request?

This pull request adds array/base/join.

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.

No.

Checklist

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


@stdlib-js/reviewers

@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 Mar 3, 2024
@kgryte kgryte changed the title feat(array/base/join) adds join in array/base/join closes #1327 feat: add array/base/join Mar 3, 2024
Signed-off-by: Athan <kgryte@gmail.com>
Signed-off-by: Athan <kgryte@gmail.com>
t.end();
});

tape( 'the function joins an array-like object (generic)', function test( t ) {
Copy link
Member

@kgryte kgryte Mar 3, 2024

Choose a reason for hiding this comment

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

You should add tests for edge cases. E.g., how are nulls and undefineds serialized? Complex number arrays? what happens for single element arrays? What about when null or undefined is the last element? What about NaN values? Etc etc. These tests should be replicated for generic, accessor, and typed arrays where appropriate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

About NaN values being treated, the current implementation converts it to a NaN string which is also the default behaviour according to mdn docs. Do we want to do it any differently?

Copy link
Contributor Author

@adityacodes30 adityacodes30 Mar 3, 2024

Choose a reason for hiding this comment

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

Also , in case of Float64 arrays and like , when their method is invoked (it treats null and undefined as per its own join implementation) , it does not produce expected behaviour treating null or undefined as an empty string as our implementation here

var x = new Float64Array( [ 1.0, 2.0, null, undefined ] );
var s = join( x, ',' );
console.log(s);
> '1,2,0,NaN'

how should i handle the writing the testcases here as they do not objectively express join , rather direct to the internal methods

Copy link
Member

@kgryte kgryte Mar 3, 2024

Choose a reason for hiding this comment

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

As mentioned above, test edge cases as appropriate. As null and undefined have no equivalent in typed arrays, don't add tests for them for Float64Array and Int32Array.

For NaN, yes, the built-in behavior is correct. Meaning, except for null and undefined, the serialized value should be equivalent to calling x[i].toString().

BTW: given that null and undefined checks are unnecessary for typed arrays, so we should add additional branching logic similar to

if ( hasMethod( x, 'join' ) {
	// Defer to method...
	return out;
}
if ( obj.accessorProtocol ) {
	// Handle accessor arrays...
	return out;
}
if ( obj.dtype === 'generic' || obj.dtype === null ) {
	// Handle generic indexed arrays and array-like objects with explicit handling of `null` and `undefined`...
	return out;
}
// Handle indexed typed arrays where handling of `null` and `undefined` is not necessary...
return out;

Signed-off-by: Athan <kgryte@gmail.com>
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.

@adityacodes30 Thank you for working on this. At the moment, this PR needs several changes in order to move forward.

As some general advice, I would encourage you to not copy-and-paste without carefully considering whether what you are doing is applicable. You copied array/base/slice, it seemed, and there are a variety of key differences between that package and this one. As such, you need to be careful and think critically about what needs to be modified.

@kgryte kgryte added the Needs Changes Pull request which needs changes before being merged. label Mar 3, 2024
@kgryte
Copy link
Member

kgryte commented Mar 3, 2024

@adityacodes30 Also, please note how I updated your OP and the PR title. The more you can reduce maintainer noise, the quicker you'll be to receive a review and the more likely that your future PRs will be merged.

@adityacodes30
Copy link
Contributor Author

got it @kgryte, thanks for the very descriptive review - does make things a lot clearer for this pr and going forward

@adityacodes30
Copy link
Contributor Author

@kgryte i have made the requested changes, let me know if any other edits are needed

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.

Left a few comments, but after these are addressed it should be ready to land, I think.

adityacodes30 and others added 5 commits March 5, 2024 10:48
Co-authored-by: Philipp Burckhardt <pburckhardt@outlook.com>
Signed-off-by: Aditya Sapra <110766802+adityacodes30@users.noreply.github.com>
Co-authored-by: Philipp Burckhardt <pburckhardt@outlook.com>
Signed-off-by: Aditya Sapra <110766802+adityacodes30@users.noreply.github.com>
Co-authored-by: Philipp Burckhardt <pburckhardt@outlook.com>
Signed-off-by: Aditya Sapra <110766802+adityacodes30@users.noreply.github.com>
Signed-off-by: Philipp Burckhardt <pburckhardt@outlook.com>
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.

LGTM! Will merge once CI has passed.

Thanks for your contributions!

@Planeshifter Planeshifter merged commit bb7817f into stdlib-js:develop Mar 5, 2024
bad-in-coding pushed a commit to bad-in-coding/stdlib that referenced this pull request Mar 7, 2024
PR-URL: stdlib-js#1463
Closes: stdlib-js#1327

---------

Signed-off-by: Athan Reines <kgryte@gmail.com>
Signed-off-by: Aditya Sapra <110766802+adityacodes30@users.noreply.github.com>
Signed-off-by: Philipp Burckhardt <pburckhardt@outlook.com>
Co-authored-by: Athan Reines <kgryte@gmail.com>
Co-authored-by: Philipp Burckhardt <pburckhardt@outlook.com>
Reviewed-by: Athan Reines <kgryte@gmail.com>
Reviewed-by: Philipp Burckhardt <pburckhardt@outlook.com>
@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. Needs Changes Pull request which needs changes before being merged. Utilities Issue or pull request concerning general utilities.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RFC]: add @stdlib/array/base/join
3 participants