"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.dedupArray = dedupArray;
exports.chunk = chunk;
exports.findLastIndex = findLastIndex;
exports.findLast = findLast;
exports.filterAsync = filterAsync;
exports.mapAsync = mapAsync;
exports.reduceAsync = reduceAsync;
exports.forEachAsync = forEachAsync;
exports.someAsync = someAsync;
exports.everyAsync = everyAsync;
exports.includesAsync = includesAsync;
exports.isArrayOf = isArrayOf;
exports.isUint8Array = isUint8Array;
function dedupArray(array) {
    return Array.from(new Set(array));
}
function chunk(array, chunkSize) {
    const chunks = [];
    for (let i = 0; i < array.length; i += chunkSize) {
        chunks.push(array.slice(i, i + chunkSize));
    }
    return chunks;
}
function findLastIndex(array, predicate) {
    for (let i = array.length - 1; i >= 0; i--) {
        if (predicate(array[i], i, array)) {
            return i;
        }
    }
    return -1;
}
function findLast(array, predicate) {
    const index = findLastIndex(array, predicate);
    return index >= 0 ? array[index] : undefined;
}
async function filterAsync(array, predicate) {
    const results = await Promise.all(array.map(predicate));
    return array.filter((_, index) => results[index]);
}
function mapAsync(array, mapper) {
    return Promise.all(array.map(mapper));
}
async function reduceAsync(array, reducer, initialValue) {
    let accumulator = initialValue;
    for (let i = 0; i < array.length; i++) {
        accumulator = await reducer(accumulator, array[i], i, array);
    }
    return accumulator;
}
async function forEachAsync(array, callback) {
    await mapAsync(array, callback);
}
async function someAsync(array, predicate) {
    const results = await mapAsync(array, predicate);
    return results.some((value) => value);
}
async function everyAsync(array, predicate) {
    return !(await someAsync(array, async (value, index, obj) => !(await predicate(value, index, obj))));
}
function includesAsync(array, predicate) {
    return someAsync(array, predicate);
}
function isArrayOf(array, predicate) {
    return Array.isArray(array) && array.every(predicate);
}
function isUint8Array(value) {
    return (Array.isArray(value) &&
        value.length > 0 &&
        value.every((item) => typeof item === "number" && Number.isInteger(item) && item >= 0 && item < 256));
}
//# sourceMappingURL=ArrayUtils.js.map