Advertisement
EmoRz

8. Validity Checker

Sep 18th, 2019
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. function solve(arr){
  3.  
  4.     let x1 = Number(arr[0]);
  5.     let y1 = Number(arr[1]);
  6.     let x2 = Number(arr[2]);
  7.     let y2 = Number(arr[3]);
  8.  
  9.     let first =  Number(distance(x1, y1,0, 0));
  10.     let second =  Number(distance(x2, y2,0, 0));
  11.     let third = Number(distance(x1, y1, x2, y2));
  12.  
  13.  
  14.     isValidNumber(first, x1, y1, 0, 0);
  15.     isValidNumber(second, x2, y2, 0, 0);
  16.     isValidNumber(third, x1, y1, x2, y2);
  17. }
  18.  
  19. //solve([3, 0, 0, 4])
  20. //solve([2, 1, 1, 1])
  21.  
  22. function distance(x1, y1, x2, y2) {
  23.    
  24.     let distX = x1 - x2;
  25.     let distY = y1 - y2;
  26.  
  27.     let result = Math.sqrt(Math.pow(distX,2)+ Math.pow(distY, 2));
  28.     return result;
  29. }
  30.  
  31. function isValidNumber(num, x1, y1, x2, y2){
  32.  
  33.     if(Number.isInteger(num)){
  34.         console.log(`{${x1}, ${y1}} to {${x2}, ${y2}} is valid`)
  35.     }
  36.     else{
  37.         console.log(`{${x1}, ${y1}} to {${x2}, ${y2}} is invalid`)
  38.  
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement