Skip to content

Instantly share code, notes, and snippets.

@joshwashywash
Last active March 4, 2023 00:29
Show Gist options
  • Save joshwashywash/1b4d3bd8765ca42b0a94ca8d9e67ec9a to your computer and use it in GitHub Desktop.
Save joshwashywash/1b4d3bd8765ca42b0a94ca8d9e67ec9a to your computer and use it in GitHub Desktop.
takes a random sample from an array

Sample an element from an array in TypeScript

const sample = <T>(items: T[]) => items[Math.floor(Math.random() * items.length)];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment