Spocoman

03. Points Validation

Jan 30th, 2022 (edited)
120
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 checkFirst = firstPoint(arr);
  8.     let checkSecond = secondPoint(arr);
  9.     let checkThird = thirdPoint(arr);
  10.  
  11.     function firstPoint() {
  12.         return Math.sqrt(Math.pow(x1, 2) + Math.pow(y1, 2));
  13.     }
  14.  
  15.     function secondPoint() {
  16.         return Math.sqrt(Math.pow(x2, 2) + Math.pow(y2, 2));
  17.     }
  18.  
  19.     function thirdPoint() {
  20.         return Math.sqrt(Math.pow(Math.abs(x2 - x1), 2) + Math.pow(Math.abs(y2 - y1), 2));
  21.     }
  22.     console.log(`{${x1}, ${y1}} to {0, 0} is ${checkFirst === Math.trunc(checkFirst) ? 'valid' : 'invalid'}`);
  23.     console.log(`{${x2}, ${y2}} to {0, 0} is ${checkSecond === Math.trunc(checkSecond) ? 'valid' : 'invalid'}`);
  24.     console.log(`{${x1}, ${y1}} to {${x2}, ${y2}} is ${checkThird === Math.trunc(checkThird) ? 'valid' : 'invalid'}`);
  25.    
  26. }
  27.  
Add Comment
Please, Sign In to add comment