Skip to content

Instantly share code, notes, and snippets.

@electerious
Created November 13, 2015 10:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save electerious/0410242d781e922a378d to your computer and use it in GitHub Desktop.
Save electerious/0410242d781e922a378d to your computer and use it in GitHub Desktop.
Limit a number between a min and max value
const limit = (min, max, num) => Math.min(Math.max(num, min), max)
@electerious
Copy link
Author

Example:

limit(0, 10, 5) // 5
limit(0, 10, 15) // 10
limit(0, 10, -5) // 0

@electerious
Copy link
Author

Moved to limit-number.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment