update: hooks, web

This commit is contained in:
Vick Scarlet
2026-08-16 20:06:16 +08:00
committed by 神戸小鳥
parent 2f91709d1e
commit 322f775796
67 changed files with 2339 additions and 2243 deletions
+15
View File
@@ -22,3 +22,18 @@ export function pickWeight<T>(items: WeightItem<T>[], rng?: RNG) {
export function sum(arr: number[]) {
return arr.reduce((sum, v) => sum + v, 0)
}
export function shuffle<T>(array: T[], rng?: RNG): T[] {
const result = [...array]
for (let i = result.length - 1; i > 0; i--) {
const j = random(i, 0, rng)
const temp = result[i]
result[i] = result[j]!
result[j] = temp!
}
return result
}
export function keys<T extends object>(obj: T): (keyof T)[] {
return Object.keys(obj) as (keyof T)[]
}