Advertisement
kristina111

Untitled

Jun 1st, 2017
2,412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(arr) {
  2.     let x1 = Number(arr[0]);
  3.     let y1 = Number(arr[1]);
  4.     let x2 = Number(arr[2]);
  5.     let y2 = Number(arr[3]);
  6.  
  7.     function distance(x1, y1, x2, y2) {
  8.         let distH = x1 - x2;
  9.         let distY = y1 - y2;
  10.         return Math.sqrt(distH**2 + distY**2);
  11.     }
  12.  
  13.     if (Number.isInteger(distance(x1, y1, 0, 0))) {
  14.         console.log(`{${x1}, ${y1}} to {0, 0} is valid`);
  15.     } else {
  16.         console.log(`{${x1}, ${y1}} to {0, 0} is invalid`);
  17.     }
  18.  
  19.     if (Number.isInteger(distance(x2, y2, 0, 0))) {
  20.         console.log(`{${x2}, ${y2}} to {0, 0} is valid`);
  21.     } else {
  22.         console.log(`{${x2}, ${y2}} to {0, 0} is invalid`);
  23.     }
  24.  
  25.     if (Number.isInteger(distance(x1, y1, x2, y2))) {
  26.         console.log(`{${x1}, ${y1}} to {${x2}, ${y2}} is valid`);
  27.     } else {
  28.         console.log(`{${x1}, ${y1}} to {${x2}, ${y2}} is invalid`);
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement