Advertisement
vladovip

Points Validation_JS Fundamentals_More EX

Feb 5th, 2022
1,178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function pointsValidation(inputArray) {
  2.   let x1 = inputArray[0];
  3.   let y1 = inputArray[1];
  4.   let x2 = inputArray[2];
  5.   let y2 = inputArray[3];
  6.   let defaulX = 0;
  7.   let defaultY = 0;
  8.  
  9.   function distanceX1Y1toX0Y0(x1, y1, defaulX, defaultY) {
  10.     let distance = Math.sqrt(
  11.       Math.pow(x1 - defaulX, 2) + Math.pow(y1 - defaultY, 2)
  12.     );
  13.     return distance;
  14.   }
  15.   let currentDistance1 = distanceX1Y1toX0Y0(x1, y1, defaulX, defaultY);
  16.  
  17.   function distanceX2Y2toX0Y0(x2, y2, defaulX, defaultY) {
  18.     let distance = Math.sqrt(
  19.       Math.pow(x2 - defaulX, 2) + Math.pow(y2 - defaultY, 2)
  20.     );
  21.     return distance;
  22.   }
  23.   let currentDistance2 = distanceX2Y2toX0Y0(x2, y2, defaulX, defaultY);
  24.  
  25.   function distanceX1Y1toX2Y2(x1, y1, x2, y2) {
  26.     let distance = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
  27.     return distance;
  28.   }
  29.   let currentDistance3 = distanceX1Y1toX2Y2(x1, y1, x2, y2);
  30.  
  31.   if (Number.isInteger(currentDistance1)) {
  32.     console.log(`{${x1}, ${y1}} to {${defaulX}, ${defaultY}} is valid`);
  33.   } else {
  34.     console.log(`{${x1}, ${y1}} to {${defaulX}, ${defaultY}} is invalid`);
  35.   }
  36.  
  37.   if (Number.isInteger(currentDistance2)) {
  38.     console.log(`{${x2}, ${y2}} to {${defaulX}, ${defaultY}} is valid`);
  39.   } else {
  40.     console.log(`{${x2}, ${y2}} to {${defaulX}, ${defaultY}} is invalid`);
  41.   }
  42.  
  43.   if (Number.isInteger(currentDistance3)) {
  44.     console.log(`{${x1}, ${y1}} to {${x2}, ${y2}} is valid`);
  45.   } else {
  46.     console.log(`{${x1}, ${y1}} to {${x2}, ${y2}} is invalid`);
  47.   }
  48.  
  49.   // console.log(`${x1, y1} to ${defaulX, defaultY} is valid`);
  50.   // console.log(`${x2, y2} to ${defaulX, defaultY} is valid`);
  51.   // console.log(`${x1, y1} to ${x2, y2} is valid`);
  52. }
  53. pointsValidation([2, 1, 1, 1]);
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement