Merge pull request #1192 from robintown/expand-collapse-inverse

Make the expand and collapse interactions inverses of one another
This commit is contained in:
Robin 2023-07-07 09:36:25 -04:00 committed by GitHub
commit 2eb548de9f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 543 additions and 321 deletions

View file

@ -22,10 +22,10 @@ limitations under the License.
// Array.prototype.findLastIndex
export function findLastIndex<T>(
array: T[],
predicate: (item: T) => boolean
predicate: (item: T, index: number) => boolean
): number | null {
for (let i = array.length - 1; i >= 0; i--) {
if (predicate(array[i])) return i;
if (predicate(array[i], i)) return i;
}
return null;
@ -34,5 +34,11 @@ export function findLastIndex<T>(
/**
* Counts the number of elements in an array that satsify the given predicate.
*/
export const count = <T>(array: T[], predicate: (item: T) => boolean): number =>
array.reduce((acc, item) => (predicate(item) ? acc + 1 : acc), 0);
export const count = <T>(
array: T[],
predicate: (item: T, index: number) => boolean
): number =>
array.reduce(
(acc, item, index) => (predicate(item, index) ? acc + 1 : acc),
0
);

File diff suppressed because it is too large Load diff