mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2024-11-10 17:04:49 +08:00
replaced .at with a function that is supported in older browsers
This commit is contained in:
parent
198493ca95
commit
0e88bd87c3
3 changed files with 15 additions and 5 deletions
|
@ -576,7 +576,9 @@ export async function init(): Promise<void> {
|
|||
}
|
||||
|
||||
if (Config.keymapMode === "next" && Config.mode !== "zen") {
|
||||
KeymapEvent.highlight(TestWords.words.getCurrent().at(0) as string);
|
||||
KeymapEvent.highlight(
|
||||
Misc.nthElementFromArray([...TestWords.words.getCurrent()], 0) as string
|
||||
);
|
||||
}
|
||||
Funbox.toggleScript(TestWords.words.getCurrent());
|
||||
TestUI.setRightToLeft(language.rightToLeft);
|
||||
|
|
|
@ -440,8 +440,8 @@ export async function generateWords(
|
|||
i,
|
||||
language,
|
||||
limit,
|
||||
ret.at(-1) ?? "",
|
||||
ret.at(-2) ?? ""
|
||||
Misc.nthElementFromArray(ret, -1) ?? "",
|
||||
Misc.nthElementFromArray(ret, -2) ?? ""
|
||||
);
|
||||
ret.push(nextWord);
|
||||
}
|
||||
|
@ -528,8 +528,8 @@ async function generateQuoteWords(
|
|||
i,
|
||||
language,
|
||||
limit,
|
||||
ret.at(-1) ?? "",
|
||||
ret.at(-2) ?? ""
|
||||
Misc.nthElementFromArray(ret, -1) ?? "",
|
||||
Misc.nthElementFromArray(ret, -2) ?? ""
|
||||
);
|
||||
ret.push(nextWord);
|
||||
}
|
||||
|
|
|
@ -1282,6 +1282,14 @@ export function randomElementFromArray<T>(array: T[]): T {
|
|||
return array[randomIntFromRange(0, array.length - 1)];
|
||||
}
|
||||
|
||||
export function nthElementFromArray<T>(
|
||||
array: T[],
|
||||
index: number
|
||||
): T | undefined {
|
||||
index = index < 0 ? array.length + index : index;
|
||||
return array[index];
|
||||
}
|
||||
|
||||
export function randomElementFromObject<T extends object>(
|
||||
object: T
|
||||
): T[keyof T] {
|
||||
|
|
Loading…
Reference in a new issue