Last active
March 10, 2018 12:13
-
-
Save DavidMellul/682b3b7050e52a43106bfb1f63a368f7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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