refactor: extract pick() helper, deduplicate random selection
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
88ceba43b0
commit
ea716c1f0e
@@ -0,0 +1,10 @@
|
||||
/** Pick a random element from an array */
|
||||
export function pick<T>(arr: T[]): T {
|
||||
return arr[Math.floor(Math.random() * arr.length)]
|
||||
}
|
||||
|
||||
/** Wrap an unknown thrown value into an Error */
|
||||
export function toError(err: unknown): Error {
|
||||
if (err instanceof Error) return err
|
||||
return new Error(String(err))
|
||||
}
|
||||
Reference in New Issue
Block a user