Files
archy/apps/did-wallet/node_modules/@tbd54566975/dwn-sdk-js/src/utils/array.ts
T
Dorian 0d073fa89e Add comprehensive installation and setup documentation
- Add GETTING_STARTED.md with quick start guide and development modes
- Add INSTALL.sh automated installation script
- Add INSTALLATION_CHECKLIST.md, INSTALLATION_SUCCESS.md, and INSTALLATION_SUMMARY.md
- Add QUICK_REFERENCE.md for common commands
- Add SETUP_GUIDE.md with detailed setup instructions
- Update README.md with improved project overview
- Add did-wallet app dependencies and node_modules
2026-01-27 17:18:21 +00:00

39 lines
1.2 KiB
TypeScript

/**
* Array utility methods.
*/
export class ArrayUtility {
/**
* Returns `true` if content of the two given byte arrays are equal; `false` otherwise.
*/
public static byteArraysEqual(array1: Uint8Array, array2:Uint8Array): boolean {
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.
*/
public static async fromAsyncGenerator<T>(iterator: AsyncGenerator<T>): Promise<Array<T>> {
const array: Array<T> = [ ];
for await (const value of iterator) {
array.push(value);
}
return array;
}
/**
* Generic asynchronous sort method.
*/
public static async asyncSort<T>(array: T[], asyncComparer: (a: T, b: T) => Promise<number>): Promise<T[]> {
// 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;
}
}