SHARE
TWEET

Untitled

a guest Sep 22nd, 2019 99 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. valid = arr => {
  2.   const [x1, y1, x2, y2] = arr;
  3.   const result= []
  4.   const a = Math.sqrt(x1 ** 2 + y1 ** 2);
  5.   const b = Math.sqrt(x2 ** 2 + y2 ** 2);
  6.   const c = Math.sqrt((y1 - y2) ** 2 + (x1 - x2) ** 2);
  7.  
  8.   const isValid = (a, x, y) =>
  9.     a === Math.floor(a)
  10.       ? result.push(`{${x}, ${y}} to {0, 0} is valid`)
  11.       : result.push(`{${x}, ${y}} to {0, 0} is invalid`);
  12.  
  13.   isValid(a, x1, y1);
  14.   isValid(b, x2, y2);
  15.  
  16.   c === Math.floor(c)
  17.     ? result.push(`{${x1}, ${y1}} to {${x2}, ${y2}} is valid`)
  18.     : result.push(`{${x1}, ${y1}} to {${x2}, ${y2}} is invalid`);
  19.     return result.join('\n')
  20. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top