refactor: 按键系统

This commit is contained in:
AncTe committed 2026-10-22 22:25:59 +08:00
1 parent d5b2a820d8
commit 564f53d82a
15 files changed
+569 -419

No files matched your search

+24
View File
@@ -20,3 +20,27 @@ export function cumsum(seq: Iterable<number>): number[] {
}
return result;
}
/**
* 判断一个数组的所有项,符合的项组成 `match`,不符合的组成 `unmatch`,返回 `[match, unmatch]`
* @param array 要判断的数组
* @param filter 判断函数
* @example matchArray([1, 2, 3, 4], v => v < 2); // [[1], [2, 3, 4]]
*/
export function matchArray<T>(
array: readonly T[],
filter: (v: T, i: number, a: readonly T[]) => boolean
): [match: T[], unmatch: T[]] {
const match: T[] = [];
const unmatch: T[] = [];
array.forEach((v, i, a) => {
if (filter(v, i, a)) {
match.push(v);
} else {
unmatch.push(v);
}
});
return [match, unmatch];
}