17 lines
No EOL
468 B
TypeScript
17 lines
No EOL
468 B
TypeScript
export class ArrayUtils {
|
|
public static chooseRandom<T>(array: Array<T>): T {
|
|
const index = Math.floor(Math.random() * array.length);
|
|
return array[index];
|
|
}
|
|
|
|
public static arraysEqual<T>(a: Array<T>, b: Array<T>): boolean {
|
|
if (a === b) return true;
|
|
if (a == null || b == null) return false;
|
|
if (a.length !== b.length) return false;
|
|
|
|
for (let i = 0; i < a.length; ++i) {
|
|
if (a[i] !== b[i]) return false;
|
|
}
|
|
return true;
|
|
}
|
|
} |