30 lines
625 B
TypeScript
30 lines
625 B
TypeScript
export async function Sleep(time: number)
|
|
{
|
|
return new Promise(res =>
|
|
{
|
|
setTimeout(res, time);
|
|
});
|
|
}
|
|
|
|
export function arrayLast<T>(arr: { [key: number]: T, length: number; }): T
|
|
{
|
|
return arr[arr.length - 1];
|
|
}
|
|
|
|
export function arrayMax<T>(arr: T[], f: (item: T) => number = a => (a as unknown as number)): [T, number]
|
|
{
|
|
let max = -Infinity;
|
|
let maxIndex = -1;
|
|
for (let i = 0; i < arr.length; i++)
|
|
{
|
|
let item = arr[i];
|
|
let v = f(item);
|
|
if (v > max)
|
|
{
|
|
maxIndex = i;
|
|
max = v;
|
|
}
|
|
}
|
|
return [arr[maxIndex], maxIndex];
|
|
}
|