Advertisement
kstoyanov

07. Validity Checker

Sep 16th, 2020
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(arr) {
  2.   const x1 = Number(arr[0]);
  3.   const y1 = Number(arr[1]);
  4.   const x2 = Number(arr[2]);
  5.   const y2 = Number(arr[3]);
  6.  
  7.   function distance(x1, y1, x2, y2) {
  8.     const distH = x1 - x2;
  9.     const distY = y1 - y2;
  10.     return Math.sqrt(distH ** 2 + distY ** 2);
  11.   }
  12.  
  13.   if (Number.isInteger(distance(x1, y1, 0, 0))) {
  14.     console.log(`{${x1}, ${y1}} to {0, 0} is valid`);
  15.   } else {
  16.     console.log(`{${x1}, ${y1}} to {0, 0} is invalid`);
  17.   }
  18.  
  19.   if (Number.isInteger(distance(x2, y2, 0, 0))) {
  20.     console.log(`{${x2}, ${y2}} to {0, 0} is valid`);
  21.   } else {
  22.     console.log(`{${x2}, ${y2}} to {0, 0} is invalid`);
  23.   }
  24.  
  25.   if (Number.isInteger(distance(x1, y1, x2, y2))) {
  26.     console.log(`{${x1}, ${y1}} to {${x2}, ${y2}} is valid`);
  27.   } else {
  28.     console.log(`{${x1}, ${y1}} to {${x2}, ${y2}} is invalid`);
  29.   }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement