Closed
Description
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
- I have read and understood the Code of Conduct.
- Searched for existing issues and pull requests.
- The issue name begins with
RFC:
.
Metadata
Metadata
Assignees
Labels
RFC feature request which has been accepted.Issue or pull request for adding a new feature.A good first issue for new contributors!Issue involves or relates to JavaScript.Request for comments. Feature requests and proposed changes.May require some initial design or R&D, but should be straightforward to resolve and/or implement.Normal priority concern or feature request.