stdlib-js / stdlib

✨ Standard library for JavaScript and Node.js. ✨
https://stdlib.io
Apache License 2.0
4.42k stars 471 forks source link

[RFC]: add `@stdlib/array/base/cuany-by-right` #2327

Closed kgryte closed 1 month ago

kgryte commented 5 months ago

Description

This RFC proposes adding the package @stdlib/array/base/cuany-by-right, which cumulatively tests whether at least one array element in a provided array passes 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 = [ 0, 1, 0, 0, 0 ];

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

var y2 = [ false, null, false, null, false, null, false, null, false, null ];
var out = cuanyByRight.assign( x, y2, 2, 0, isPositive );
// returns [ false, null, false, null, false, null, true, 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

Checklist

Aarya01Patil commented 3 months ago

@kgryte May i work on this issue ?

DevMhrn commented 3 months ago

@kgryte Please assign it to me