Advertisement
didkoslawow

Points Validation

Feb 4th, 2023
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function pointsValidation(coordinates) {
  2.     const x1 = coordinates.shift();
  3.     const y1 = coordinates.shift();
  4.     const x2 = coordinates.shift();
  5.     const y2 = coordinates.shift();
  6.  
  7.     const pointsDistance = (x1, y1, x2, y2) => {
  8.         return Math.sqrt(((Math.abs(x2 - x1)) ** 2) + ((Math.abs(y2 - y1)) ** 2));
  9.     }
  10.  
  11.     if (Number.isInteger(pointsDistance(x1, y1, 0, 0))) {
  12.         console.log(`{${x1}, ${y1}} to {0, 0} is valid`);
  13.     } else {
  14.         console.log(`{${x1}, ${y1}} to {0, 0} is invalid`);
  15.     }
  16.     if (Number.isInteger(pointsDistance(x2, y2, 0, 0))) {
  17.         console.log(`{${x2}, ${y2}} to {0, 0} is valid`);
  18.     } else {
  19.         console.log(`{${x2}, ${y2}} to {0, 0} is invalid`);
  20.     }
  21.     if (Number.isInteger(pointsDistance(x1, y1, x2, y2))) {
  22.         console.log(`{${x1}, ${y1}} to {${x2}, ${y2}} is valid`);
  23.     } else {
  24.         console.log(`{${x1}, ${y1}} to {${x2}, ${y2}} is invalid`);
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement