Skip to content

Instantly share code, notes, and snippets.

@elpddev
Created November 15, 2022 08:01
Show Gist options
  • Save elpddev/9b6b20828abcefaacdde368758841b9f to your computer and use it in GitHub Desktop.
Save elpddev/9b6b20828abcefaacdde368758841b9f to your computer and use it in GitHub Desktop.
Clamp number to a range. If below min then min, If above max then max
const clamp = (min: number, max: number, val: number) =>
Math.max(min, Math.min(val, max));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment