Skip to content
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

Added iterCuEveryBy function and test #2747

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions iterCuEveryBy/iterCuEveryBy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Import the necessary module
var array2iterator = require('@stdlib/array/to-iterator');

Check failure on line 2 in iterCuEveryBy/iterCuEveryBy.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Use the global form of 'use strict'

Check failure on line 2 in iterCuEveryBy/iterCuEveryBy.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

'array2iterator' is assigned a value but never used

Check failure on line 2 in iterCuEveryBy/iterCuEveryBy.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

There should be exactly one space after the opening parenthesis in require calls

Check failure on line 2 in iterCuEveryBy/iterCuEveryBy.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

There should be exactly one space before the closing parenthesis in require calls

// Define the function iterCuEveryBy
function iterCuEveryBy(iterator, predicate) {

Check failure on line 5 in iterCuEveryBy/iterCuEveryBy.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Missing JSDoc comment
let index = 0; // to keep track of the iteration index

Check failure on line 6 in iterCuEveryBy/iterCuEveryBy.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Expected indentation of 1 tab but found 4 spaces

Check failure on line 6 in iterCuEveryBy/iterCuEveryBy.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Block-scoped variables in non-strict mode are not supported until Node.js 6.0.0. The configured version range is '>=0.12.18'
let cumulated = true; // to track cumulative test result

Check failure on line 7 in iterCuEveryBy/iterCuEveryBy.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Expected indentation of 1 tab but found 4 spaces

Check failure on line 7 in iterCuEveryBy/iterCuEveryBy.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Block-scoped variables in non-strict mode are not supported until Node.js 6.0.0. The configured version range is '>=0.12.18'

return {

Check failure on line 9 in iterCuEveryBy/iterCuEveryBy.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Expected indentation of 1 tab but found 4 spaces
next() {
const nextValue = iterator.next();
if (nextValue.done) {
return { value: undefined, done: true };
}

cumulated = cumulated && predicate(nextValue.value, index++);
return { value: cumulated, done: false };
}
};
}

// Export the function for use in other files
module.exports = iterCuEveryBy;
22 changes: 22 additions & 0 deletions iterCuEveryBy/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Import the necessary modules
var array2iterator = require('@stdlib/array/to-iterator');
var iterCuEveryBy = require('./iterCuEveryBy');

// Define a predicate function
function isPositive(value) {
return (value > 0);
}

// Convert an array to an iterator
var arr = array2iterator([1, 1, 1, 0, 1]);

// Create a cumulative test iterator
var it = iterCuEveryBy(arr, isPositive);

// Test the iterator
console.log(it.next().value); // true
console.log(it.next().value); // true
console.log(it.next().value); // true
console.log(it.next().value); // false
console.log(it.next().value); // false
console.log(it.next().done); // true
Loading