Skip to content

Instantly share code, notes, and snippets.

@BrianHicks
Created April 18, 2013 20:56
Show Gist options
  • Save BrianHicks/5416151 to your computer and use it in GitHub Desktop.
Save BrianHicks/5416151 to your computer and use it in GitHub Desktop.
function inRange(min, max, value) {
return (min == null || min <= value) &&
(max == null || max >= value)
}
// evalutation of inRange(1, 2, 1.5)
(1 == null || 1 <= 1) && (2 == null || 2 >= 1)
(false || true) && (false || true)
true && true
true
// evaluation of inRange(1, null, 1.5)
(1 == null || 1 <= 1.5) && (null == null || null >= 1.5)
(false || true) && (true || false)
true && true
true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment