partitioned-loops
v1.0.4
Published
Library for partitioned loops organization
Downloads
607
Maintainers
Readme
partitioned-loops
Library for partitioned loops organization
Install
npm i partitioned-loops
Usage
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 }
);
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 }
);