Advertisement
vladovip

Points of validation

Feb 7th, 2021
416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function pointsValidation(arr) {
  2.     let x1 = arr[0];
  3.     let y1 = arr[1];
  4.     let x2 = arr[2];
  5.     let y2 = arr[3];
  6.  
  7.     let checkFirstPoint = firstPoint(arr);
  8.     let checkSecondPoint = secondPoint(arr);
  9.     let checkThirdPoint = thirdPoint(arr);
  10.  
  11.     if (checkFirstPoint === Math.trunc(checkFirstPoint)) {
  12.         console.log(`{${x1}, ${y1}} to {0, 0} is valid`);
  13.     } else {
  14.         console.log(`{${x1}, ${y1}} to {0, 0} is invalid`);
  15.     }
  16.  
  17.     if (checkSecondPoint === Math.trunc(checkSecondPoint)) {
  18.         console.log(`{${x2}, ${y2}} to {0, 0} is valid`);
  19.     } else {
  20.         console.log(`{${x2}, ${y2}} to {0, 0} is invalid`);
  21.     }
  22.  
  23.     if (checkThirdPoint === Math.trunc(checkThirdPoint)) {
  24.         console.log(`{${x1}, ${y1}} to {${x2}, ${y2}} is valid`);
  25.     } else {
  26.         console.log(`{${x1}, ${y1}} to {${x2}, ${y2}} is invalid`);
  27.     }
  28.  
  29.  
  30.  
  31.     function firstPoint() {
  32.         let checkOne = Math.sqrt(Math.pow(x1, 2) + Math.pow(y1, 2));
  33.  
  34.  
  35.         return checkOne;
  36.     }
  37.  
  38.     function secondPoint() {
  39.         let checkTwo = Math.sqrt(Math.pow(x2, 2) + Math.pow(y2, 2));
  40.         return checkTwo;
  41.     }
  42.  
  43.     function thirdPoint() {
  44.         let checkThree = Math.sqrt(Math.pow(Math.abs(x2 - x1), 2) + Math.pow(Math.abs(y2 - y1), 2));
  45.         return checkThree;
  46.       }
  47.  
  48.  
  49. }
  50. pointsValidation([2, 1, 1, 1])
  51. pointsValidation([3, 0, 0, 4])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement