-
Notifications
You must be signed in to change notification settings - Fork 0
Async Find Index
zak-zaffar edited this page Dec 23, 2019
·
6 revisions
/**
* Async Find Index
* Find an item's index in an iterable object asynchronously and resolve when found or all callbacks resolve
* @async
* @param {Function} callback - callback(currentValue, index, array)
* @param {Object} [thisArg] - must be iterable
* @return {Number} - an integer index, -1 if not found
* @throws {TypeError}
*/
async function asyncFind(callback, [thisArg]) {...}
const { asyncFind } = require('iterable-async'),
aarray = [1, 2, 3];
const found = await asyncFindIndex(async element => {
return element > 2;
}, array);
console.log('Resolved Index ' + found);
// Resolved Index 2
const { asyncFind } = require('iterable-async'),
array = [1, 2, 3];
array.asyncFindIndex = asyncFindIndex;
const found = await array.asyncFindIndex(async element => {
return element > 2;
});
console.log('Resolved Index ' + found);
// Resolved Index 2