mirror of
https://github.com/ankitects/anki.git
synced 2025-09-25 01:06:35 -04:00
Fix regression from 70c3b51b0b
Negative indices were not treated correctly (as offset from end)
This commit is contained in:
parent
7563a3c929
commit
7cd779063f
1 changed files with 11 additions and 3 deletions
|
@ -8,11 +8,19 @@ function normalize<T extends Identifiable>(
|
||||||
values: T[],
|
values: T[],
|
||||||
idOrIndex: string | number
|
idOrIndex: string | number
|
||||||
): number {
|
): number {
|
||||||
|
let normalizedIndex: number;
|
||||||
|
|
||||||
if (typeof idOrIndex === "string") {
|
if (typeof idOrIndex === "string") {
|
||||||
return values.findIndex((value) => value.id === idOrIndex);
|
normalizedIndex = values.findIndex((value) => value.id === idOrIndex);
|
||||||
} else {
|
|
||||||
return idOrIndex >= values.length ? -1 : idOrIndex;
|
|
||||||
}
|
}
|
||||||
|
else if (idOrIndex < 0) {
|
||||||
|
normalizedIndex = values.length + idOrIndex;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
normalizedIndex = idOrIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
return normalizedIndex >= values.length ? -1 : normalizedIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function search<T extends Identifiable>(
|
export function search<T extends Identifiable>(
|
||||||
|
|
Loading…
Reference in a new issue