Skip to content

Instantly share code, notes, and snippets.

@DavidMellul
Last active March 10, 2018 12:13
Show Gist options
  • Save DavidMellul/682b3b7050e52a43106bfb1f63a368f7 to your computer and use it in GitHub Desktop.
Save DavidMellul/682b3b7050e52a43106bfb1f63a368f7 to your computer and use it in GitHub Desktop.
const PRECISION = 0.2; // Often called a Delta
function isValid(time) { // Ensures 1 second has elapsed
const expected = 1;
// We only assert this : (expected - precision) <= time <= (expected + precision)
return (expected - PRECISION <= time) && (expected + PRECISION >= time);
}
console.log(isValid(1.105));
// => true
console.log(isValid(0.95));
// => true
console.log(isValid(2));
// => false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment