/**
 * Array utility methods.
 */
export class ArrayUtility {
    /**
     * Returns `true` if content of the two given byte arrays are equal; `false` otherwise.
     */
    static byteArraysEqual(array1, array2) {
        const equal = array1.length === array2.length && array1.every((value, index) => value === array2[index]);
        return equal;
    }
    /**
     * Asynchronously iterates an {AsyncGenerator} to return all the values in an array.
     */
    static async fromAsyncGenerator(iterator) {
        const array = [];
        for await (const value of iterator) {
            array.push(value);
        }
        return array;
    }
    /**
     * Generic asynchronous sort method.
     */
    static async asyncSort(array, asyncComparer) {
        // this is a bubble sort implementation
        for (let i = 0; i < array.length; i++) {
            for (let j = i + 1; j < array.length; j++) {
                const comparison = await asyncComparer(array[i], array[j]);
                if (comparison > 0) {
                    [array[i], array[j]] = [array[j], array[i]]; // Swap
                }
            }
        }
        return array;
    }
}
//# sourceMappingURL=array.js.map