A library that contains simple extensions for nodejs arrays.
npm install node-array-extShell
npm install node-array-ext
`$3
`Shell
tsd install node-array-ext
`
___
$3
#### Description:
This method iterates through the elements of the array and triggers a callback after all of the elements have been processed.\- note that this method does not preserve order and allows elements to be processed asynchronously.
#### Params:
* array:
* Array<T>
* The array to process.
* each:
* (i: number, element: T, done: (err?: Error) => void) => void
* The method that will be called for each element.
* cb:
* (err?: Error) => void
* The callback that will be triggered when iteration is complete.
#### Example:
`Javascript
var extensions = require("node-array-ext");var a = [ "Hello", "World", "SomethingElse" ];
function finished(err) {
if(err) {
console.log(err);
}
else {
console.log("Complete.");
}
}
function each(i, e, done) {
setTimeout(function() {
console.log("%s => %s", i, e);
done();
}, 100 * (3 - i));
}
extensions.asyncEach(a, each, finished);
// Output:
// 3 => SomethingElse
// 2 => World
// 1 => Hello
// Complete.
`
___
$3
#### Description:
This method iterates though the elements of the array in order and triggers a callback after all of the elements have been processed.\- note that this method preserves the order and forces synchronous processing of the elements.
#### Parameters:
* array:
* Array<T>
* The array to process.
* each:
* (i: number, element: T, done: (err?: Error) => void) => void
* The method that will be called for each element.
* cb:
* (err?: Error) => void
* The callback that will be triggered when iteration is complete.
#### Example:
`Javascript
var extensions = require("node-array-ext");var a = [ "Hello", "World", "SomethingElse" ];
function finished(err) {
if(err) {
console.log(err);
}
else {
console.log("Complete.");
}
}
function each(i, e, next) {
setTimeout(function() {
console.log("%s => %s", i, e);
next();
}, 100 * (3 - i));
}
extensions.awaitEach(a, each, finished);
// Output:
// 1 => Hello
// 2 => World
// 3 => SomethingElse
// Complete.
``