https://github.com/litichevskiydv/partitioned-loops
Library for partitioned loops organization
https://github.com/litichevskiydv/partitioned-loops
Last synced: 5 months ago
JSON representation
Library for partitioned loops organization
- Host: GitHub
- URL: https://github.com/litichevskiydv/partitioned-loops
- Owner: litichevskiydv
- License: mit
- Created: 2019-06-04T05:59:54.000Z (about 6 years ago)
- Default Branch: develop
- Last Pushed: 2023-01-19T04:00:16.000Z (over 2 years ago)
- Last Synced: 2024-04-26T18:21:27.116Z (about 1 year ago)
- Language: JavaScript
- Size: 460 KB
- Stars: 0
- Watchers: 0
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# partitioned-loops
[](https://www.npmjs.com/package/partitioned-loops)
[](https://www.npmjs.com/package/partitioned-loops)
[](https://www.npmjs.com/package/partitioned-loops)
[](https://github.com/litichevskiydv/partitioned-loops/actions/workflows/ci.yaml)
[](https://coveralls.io/github/litichevskiydv/partitioned-loops?branch=master)Library for partitioned loops organization
# Install
`npm i partitioned-loops`
# Usage
```javascript
const { forEachAsync } = require("partitioned-loops");/*...*/
const finalState = await forEachAsync(
[1, 2, 3, 4, 5],
(currentValue, loopState) => {
if (currentValue > 4) loopState.break = true;
else loopState.sum += currentValue;
},
{ sum: 0 }
);
``````javascript
const { forAsync } = require("partitioned-loops");/*...*/
const array = [1, 2, 3, 4, 5];
const finalState = await forAsync(
0,
array.length,
(i, loopState) => {
if (array[i] > 4) loopState.break = true;
else loopState.sum += array[i];
},
{ sum: 0 }
);
```