fix zindex to account for group boundaries (#2065)

This commit is contained in:
David Luzar 2020-09-11 17:06:07 +02:00 committed by GitHub
parent ea020f2c50
commit d07099aadd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 1287 additions and 416 deletions

View file

@ -254,3 +254,39 @@ export const muteFSAbortError = (error?: Error) => {
}
throw error;
};
export const findIndex = <T>(
array: readonly T[],
cb: (element: T, index: number, array: readonly T[]) => boolean,
fromIndex: number = 0,
) => {
if (fromIndex < 0) {
fromIndex = array.length + fromIndex;
}
fromIndex = Math.min(array.length, Math.max(fromIndex, 0));
let i = fromIndex - 1;
while (++i < array.length) {
if (cb(array[i], i, array)) {
return i;
}
}
return -1;
};
export const findLastIndex = <T>(
array: readonly T[],
cb: (element: T, index: number, array: readonly T[]) => boolean,
fromIndex: number = array.length - 1,
) => {
if (fromIndex < 0) {
fromIndex = array.length + fromIndex;
}
fromIndex = Math.min(array.length - 1, Math.max(fromIndex, 0));
let i = fromIndex + 1;
while (--i > -1) {
if (cb(array[i], i, array)) {
return i;
}
}
return -1;
};