Fix regression from 70c3b51b0b
Negative indices were not treated correctly (as offset from end)
This commit is contained in:
parent
7563a3c929
commit
7cd779063f
@ -8,11 +8,19 @@ function normalize<T extends Identifiable>(
|
||||
values: T[],
|
||||
idOrIndex: string | number
|
||||
): number {
|
||||
let normalizedIndex: number;
|
||||
|
||||
if (typeof idOrIndex === "string") {
|
||||
return values.findIndex((value) => value.id === idOrIndex);
|
||||
} else {
|
||||
return idOrIndex >= values.length ? -1 : idOrIndex;
|
||||
normalizedIndex = values.findIndex((value) => value.id === idOrIndex);
|
||||
}
|
||||
else if (idOrIndex < 0) {
|
||||
normalizedIndex = values.length + idOrIndex;
|
||||
}
|
||||
else {
|
||||
normalizedIndex = idOrIndex;
|
||||
}
|
||||
|
||||
return normalizedIndex >= values.length ? -1 : normalizedIndex;
|
||||
}
|
||||
|
||||
export function search<T extends Identifiable>(
|
||||
|
Loading…
Reference in New Issue
Block a user