p5-analysis
Version:
API to find, create, and analyze p5.js sketch files.
29 lines (28 loc) • 963 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.asyncSome = exports.asyncFind = exports.asyncFilter = void 0;
async function asyncFilter(array, predicate, thisArg) {
const indications = await Promise.all(array.map(predicate, thisArg));
return array.filter((_value, index) => indications[index]);
}
exports.asyncFilter = asyncFilter;
async function asyncFind(array, predicate, thisArg) {
for (let i = 0; i < array.length; i++) {
const element = array[i];
if (await predicate.call(thisArg, element, i, array)) {
return element;
}
}
return undefined;
}
exports.asyncFind = asyncFind;
async function asyncSome(array, predicate, thisArg) {
for (let i = 0; i < array.length; i++) {
const element = array[i];
if (await predicate.call(thisArg, element, i, array)) {
return true;
}
}
return false;
}
exports.asyncSome = asyncSome;
;