Advertisement
Pesho_N

Untitled

Jul 24th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. function tripLength(coordinates){
  2. let x1 = coordinates[0], y1 = coordinates[1];
  3. let x2 = coordinates[2], y2 = coordinates[3];
  4. let x3 = coordinates[4], y3 = coordinates[5];
  5.  
  6. let AB = distance(x1,y1,x2,y2);
  7. let BC = distance(x2,y2,x3,y3);
  8. let AC = distance(x1,y1,x3,y3);
  9.  
  10. if (BC == AB){
  11. console.log("1->2->3: " + (AB + BC));
  12. } else if (AC < AB && BC < AB){
  13. console.log("1->3->2: " + (AC + BC));
  14. } else if ((AB + BC) > (AB + AC)){
  15. console.log("2->1->3: " + (AB + AC))
  16. }
  17.  
  18. function distance(x1,y1,x2,y2){
  19. let distance = Math.sqrt(Math.pow((x2-x1),2) + Math.pow((y2-y1),2));
  20. return distance;
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement