Advertisement
kStoikow

qwe

Jul 3rd, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function distance(array) {
  2.     let result = checkDistance();
  3.     console.log(result);
  4.  
  5.     function checkDistance() {
  6.         let x1 = array.shift();
  7.         let y1 = array.shift();
  8.         let x2 = array.shift();
  9.         let y2 = array.shift();
  10.         let toPrint = '';
  11.  
  12.         let xPointToZero = Math.sqrt(Math.pow((x1 - 0), 2) + Math.pow((y1 - 0), 2));
  13.         let yPointToZero = Math.sqrt(Math.pow((y1 - 0), 2) + Math.pow((y2 - 0), 2));
  14.         let distanceBetweenPoints = Math.sqrt(Math.pow((x2 - x1), 2) + Math.pow((y2 - y1), 2));
  15.  
  16.         if (Number.isInteger(xPointToZero)) {
  17.             toPrint += `{${x1}, ${y1}} to {0, 0} is valid\n`;
  18.         } else {
  19.             toPrint += `{${x1}, ${y1}} to {0, 0} is invalid\n`;
  20.         }
  21.  
  22.         if (Number.isInteger(yPointToZero)) {
  23.             toPrint += `{${x2}, ${y2}} to {0, 0} is valid\n`;
  24.         } else {
  25.             toPrint += `{${x2}, ${y2}} to {0, 0} is invalid\n`;
  26.         }
  27.  
  28.         if (Number.isInteger(distanceBetweenPoints)) {
  29.             toPrint += `{${x1}, ${y1}} to {${x2}, ${y2}} is valid\n`;
  30.         } else {
  31.             toPrint += `{${x1}, ${y1}} to {${x2}, ${y2}} is invalid\n`;
  32.         }
  33.  
  34.         return toPrint;
  35.     }
  36. }
  37. distance([3, 0, 8, 0])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement