Skip to content

Commit

Permalink
fix: minor clean-up and increment index correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Planeshifter committed Oct 9, 2024
1 parent 8f7f0c0 commit 0f6e120
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
8 changes: 4 additions & 4 deletions lib/node_modules/@stdlib/iter/cusome-by/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var iterCuSomeBy = require( '@stdlib/iter/cusome-by' );

#### iterCuSomeBy( iterator, n, predicate\[, thisArg] )

Returns an [iterator][mdn-iterator-protocol] which cumulatively tests whether every iterated value passes a test implemented by a `predicate` function.
Returns an [iterator][mdn-iterator-protocol] which cumulatively tests whether at least `n` iterated values pass a test implemented by a `predicate` function.

```javascript
var array2iterator = require( '@stdlib/array/to-iterator' );
Expand All @@ -53,7 +53,7 @@ function isPositive( v ) {

var arr = array2iterator( [ 0, 0, 0, 1, 1 ] );

var it = iterCuSomeBy( arr, 2, predicate );
var it = iterCuSomeBy( arr, 2, isPositive );

var v = it.next().value;
// returns false
Expand Down Expand Up @@ -162,8 +162,8 @@ var opts = {
};
var riter = randu( opts );

// Create an iterator which cumulatively tests whether every iterated value is above threshold:
var it = iterCuSomeBy( riter, 5, threshold );
// Create an iterator which tracks whether at least two values have exceeded the threshold:
var it = iterCuSomeBy( riter, 2, threshold );

// Perform manual iteration...
var r;
Expand Down
4 changes: 2 additions & 2 deletions lib/node_modules/@stdlib/iter/cusome-by/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

{{alias}}( iterator, n, predicate[, thisArg] )
Returns an iterator which cumulatively tests whether at least `n` iterated values
pass a test implemented by a predicate function.
Returns an iterator which cumulatively tests whether at least `n` iterated
values pass a test implemented by a predicate function.

If an environment supports Symbol.iterator and a provided iterator is
iterable, the returned iterator is iterable.
Expand Down
2 changes: 1 addition & 1 deletion lib/node_modules/@stdlib/iter/cusome-by/examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var opts = {
};
var riter = randu( opts );

// Create an iterator which tracks whether at least 5 values have exceeded the threshold:
// Create an iterator which tracks whether at least two values have exceeded the threshold:
var it = iterCuSomeBy( riter, 2, threshold );

// Perform manual iteration...
Expand Down
3 changes: 2 additions & 1 deletion lib/node_modules/@stdlib/iter/cusome-by/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function iterCuSomeBy( iterator, n, predicate, thisArg ) {
throw new TypeError( format( 'invalid argument. Second argument must be a positive integer. Value: `%s`.', n ) );
}
if ( !isFunction( predicate ) ) {
throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', predicate ) );
throw new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', predicate ) );
}
count = 0;
i = -1;
Expand Down Expand Up @@ -120,6 +120,7 @@ function iterCuSomeBy( iterator, n, predicate, thisArg ) {
FLG = true;
return v;
}
i += 1;
if ( !value && predicate.call( thisArg, v.value, i ) ) {
count += 1;
if ( count === n ) {
Expand Down
2 changes: 1 addition & 1 deletion lib/node_modules/@stdlib/iter/cusome-by/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ tape( 'if provided an "empty" iterator, the function returns an iterator which i
t.end();
});

tape( 'the function returns an iterator which cumulatively tests whether every iterated value passes a test implemented by a predicate function', function test( t ) {
tape( 'the function returns an iterator which cumulatively tests whether at least `n` iterated values pass a test', function test( t ) {
var expected;
var actual;
var values;
Expand Down

0 comments on commit 0f6e120

Please sign in to comment.