Guest User

Untitled

a guest
Mar 19th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. const PRECISION = 0.2; // Often called a Delta
  2.  
  3. function isValid(time) { // Ensures 1 second has elapsed
  4. const expected = 1;
  5.  
  6. // We only assert this : (expected - precision) <= time <= (expected + precision)
  7. return (expected - PRECISION <= time) && (expected + PRECISION >= time);
  8. }
  9.  
  10. console.log(isValid(1.105));
  11. // => true
  12.  
  13. console.log(isValid(0.95));
  14. // => true
  15.  
  16. console.log(isValid(2));
  17. // => false
Add Comment
Please, Sign In to add comment