Todorov_Stanimir

03. Points Validation Functions - More Exercise

Jun 11th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function pointsValidation(input) {
  2.     let [x1, y1, x2, y2] = [input[0], input[1], input[2], input[3]];
  3.  
  4.     isValidPoints(x1, y1, 0, 0);
  5.     isValidPoints(x2, y2, 0, 0);
  6.     isValidPoints(x1, y1, x2, y2);
  7.    
  8.     function isValidPoints (x1, y1, x2, y2)  {
  9.         let distane = Math.sqrt(Math.abs(x2 - x1) * Math.abs(x2 - x1) + Math.abs(y2 - y1) * Math.abs(y2 - y1));
  10.         if (distane === parseInt(distane)) {
  11.             console.log(`{${x1}, ${y1}} to {${x2}, ${y2}} is valid`);
  12.         } else {
  13.             console.log(`{${x1}, ${y1}} to {${x2}, ${y2}} is invalid`);
  14.         }
  15.     }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment