Advertisement
nikolayneykov

Untitled

Apr 30th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(coordinates) {
  2.     let pointA = { x: coordinates[0], y: coordinates[1] };
  3.     let pointB = { x: coordinates[2], y: coordinates[3] };
  4.     let pointC = { x: 0, y: 0 };
  5.  
  6.     let aToCDistance = Math.sqrt(Math.pow(pointA.x - pointC.x, 2) + Math.pow(pointA.y - pointC.y, 2));
  7.     let bToCDistance = Math.sqrt(Math.pow(pointB.x - pointC.x, 2) + Math.pow(pointB.y - pointC.y, 2));
  8.     let aToBDistance = Math.sqrt(Math.pow(pointA.x - pointB.x, 2) + Math.pow(pointA.y - pointB.y, 2));
  9.  
  10.     let aToCResult = Number.isInteger(aToCDistance) ? 'valid' : 'invalid';
  11.     let bToCResult = Number.isInteger(bToCDistance) ? 'valid' : 'invalid';
  12.     let aToBResult = Number.isInteger(aToBDistance) ? 'valid' : 'invalid';
  13.  
  14.     console.log(`{${pointA.x}, ${pointA.y}} to {${pointC.x}, ${pointC.y}} is ${aToCResult}`);
  15.     console.log(`{${pointB.x}, ${pointB.y}} to {${pointC.x}, ${pointC.y}} is ${bToCResult}`);
  16.     console.log(`{${pointA.x}, ${pointA.y}} to {${pointB.x}, ${pointB.y}} is ${aToBResult}`);
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement