stdlib icon indicating copy to clipboard operation
stdlib copied to clipboard

[RFC]: add `@stdlib/array/base/cusome-by-right`

Open kgryte opened this issue 1 year ago • 8 comments

Description

This RFC proposes adding the package @stdlib/array/base/cusome-by-right, which cumulatively tests whether at least n array elements in a provided array pass a test implemented by a predicate function, while iterating from right-to-left. The function should return a new generic array. The package should also provide an #assign API for setting output values in a provided output array.

function isPositive( value ) {
	return ( value > 0 );
}

var x = [ 1, 1, 0, 0, 0 ];

var y1 = cusomeByRight( x, 2, isPositive );
// returns [ false, false, false, false, true ]

var y2 = [ false, null, false, null, false, null, false, null, false, null ];
var out = cusomeByRight.assign( x, 2, y2, 2, 0, isPositive );
// returns [ false, null, false, null, false, null, false, null, true, null ]

var bool = ( out === y2 );
// returns true

where the assign API supports an offset and stride (see, e.g., @stdlib/array/base/take). Note that, by iterating from right to left, the values in the output array are equivalent to having first reversed the input array x and then using left-to-right iteration.

Both APIs should support accessor arrays (see, e.g., @stdlib/array/base/take).

Related Issues

No.

Questions

No.

Other

  • See also @stdlib/utils/some-by-right

Checklist

  • [X] I have read and understood the Code of Conduct.
  • [X] Searched for existing issues and pull requests.
  • [X] The issue name begins with RFC:.

kgryte avatar Jun 08 '24 00:06 kgryte

@kgryte May i work on this issue ? It is labelled as good first issue, it might help me to start contributing to this organization.

BarryByte avatar Jul 17 '24 18:07 BarryByte

@kgryte Can you assign this issue to me?

AbhinavKRN avatar Jul 27 '24 17:07 AbhinavKRN

Hey @kgryte I want to work on this issue.....plz assign this issue to me !!

srivastavaarpit977 avatar Jul 27 '24 18:07 srivastavaarpit977

:rotating_light: Important: PLEASE READ :rotating_light:

This issue has been labeled as a good first issue and is available for anyone to work on.

If this is your first time contributing to an open source project, some aspects of the development process may seem unusual, arcane, or some combination of both.

  1. You cannot "claim" issues. People new to open source often want to "claim" or be assigned an issue before beginning work. The typical rationale is that people want to avoid wasted work in the event that someone else ends up working the issue. However, this practice is not effective in open source, as it often leads to "issue squatting", in which an individual asks to be assigned, is granted their request, and then never ends up working on the issue. Accordingly, you are encouraged to communicate your intent to address this issue, ideally by providing a rough outline as to how you plan to address the issue or asking clarifying questions, but, at the end of the day, we will take running code and rough consensus in order to move forward quickly.
  2. We have a very high bar for contributions. We have very high standards for contributions and expect all contributions—whether new features, tests, or documentation—to be rigorous, thorough, and complete. Once a pull request is merged into stdlib, that contribution immediately becomes the collective responsibility of all maintainers of stdlib. When we merge code into stdlib, we are saying that we, the maintainers, commit to reviewing subsequent changes and making bugfixes to the code. Hence, in order to ensure future maintainability, this naturally leads to a higher standard of contribution.

Before working on this issue and opening a pull request, please read the project's contributing guidelines. These guidelines and the associated development guide provide important information, including links to stdlib's Code of Conduct, license policy, and steps for setting up your local development environment.

To reiterate, we strongly encourage you to refer to our contributing guides before beginning work on this issue. Failure to follow our guidelines significantly decreases the likelihood that you'll successfully contribute to stdlib and may result in automatic closure of a pull request without review.

Setting up your local development environment is a critical first step, as doing so ensures that automated development processes for linting, license verification, and unit testing can run prior to authoring commits and pushing changes. If you would prefer to avoid manual setup, we provide pre-configured development containers for use locally or in GitHub Codespaces.

We place a high value on consistency throughout the stdlib codebase. We encourage you to closely examine other packages in stdlib and attempt to emulate the practices and conventions found therein.

  • If you are attempting to contribute a new package, sometimes the best approach is to simply copy the contents of an existing package and then modify the minimum amount necessary to implement the feature (e.g., changing descriptions, parameter names, and implementation).
  • If you are contributing tests, find a package implementing a similar feature and emulate the tests of that package.
  • If you are updating documentation, examine several similar packages and emulate the content, style, and prose of those packages.

In short, the more effort you put in to ensure that your contribution looks and feels like stdlib—including variables names, bracket spacing, line breaks, etc—the more likely that your contribution will be reviewed and ultimately accepted. We encourage you to closely study the codebase before beginning work on this issue.

:sparkles: Thank you again for your interest in stdlib, and we look forward to reviewing your future contriubtions. :sparkles:

stdlib-bot avatar Aug 02 '24 00:08 stdlib-bot

Hi, is it expected to use @stdlib/utils/some-by-right to implement @stdlib/array/base/cusome-by-right ? If so, doesn’t this approach result in quadratic time complexity?

GittyHarsha avatar Aug 06 '24 08:08 GittyHarsha

@GittyHarsha No, you should not use @stdlib/utils/some-by-right to implement the proposed API. The implementation should be similar to other similar packages in @stdlib/array/base.

kgryte avatar Aug 06 '24 09:08 kgryte

Hi, I got a doubt while implementing the #assign API. In reference to @stdlib/array/base/take/lib/assign.js, the accessor arrays of type complex and boolean are explicitly handled. I think for @stdlib/array/base/cusome-by-right, there is no need to explicitly handle any types of accessor arrays?

GittyHarsha avatar Aug 10 '24 10:08 GittyHarsha

@GittyHarsha You do need to handle accessor arrays; however, I think you are right that you don't need to special case either ComplexXXArrays or BooleanArray.

E.g., in https://github.com/stdlib-js/stdlib/blob/develop/lib/node_modules/%40stdlib/array/base/cuany/lib/assign.js, we special case complex and boolean arrays, with a fallback to a general accessor utility. For your case, I think you only need the general accessor utility.

kgryte avatar Aug 10 '24 10:08 kgryte