Advertisement
Guest User

Untitled

a guest
Sep 30th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. function solve(input1) {
  2. input = input1.map(Number);
  3. let pointA = {x:input[0], y:input[1]}
  4. let pointB = {x:input[2], y:input[3]};
  5. let pointZero = {x:0, y:0};
  6. function distance(pointA, pointB) {
  7. return Math.sqrt(Math.pow(pointA.x-pointB.x) + Math.pow(pointA.y-pointB.y));
  8. }
  9. let a = distance(pointA,pointZero);
  10. console.log(a);
  11.  
  12. function isNum(distance, pointA, pointB) {
  13. if(isNaN(distance)){
  14. console.log(`{${pointA.x},${pointA.y}} to {${pointB.x}, ${pointB.y}} is invalid`)
  15. }
  16. else{
  17. console.log(`{${pointA.x},${pointA.y}} to {${pointB.x}, ${pointB.y}} is valid`)
  18. }
  19. }
  20.  
  21. isNum(distance(pointA, pointZero), pointA, pointZero);
  22. isNum(distance(pointB, pointZero), pointB, pointZero);
  23. isNum(distance(pointA, pointB), pointA, pointB);
  24.  
  25. }
  26. solve(['3', '0', '0', '4']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement