Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function tripLength(coordinates){
- let x1 = coordinates[0], y1 = coordinates[1];
- let x2 = coordinates[2], y2 = coordinates[3];
- let x3 = coordinates[4], y3 = coordinates[5];
- let AB = distance(x1,y1,x2,y2);
- let BC = distance(x2,y2,x3,y3);
- let AC = distance(x1,y1,x3,y3);
- if (BC == AB){
- console.log("1->2->3: " + (AB + BC));
- } else if (AC < AB && BC < AB){
- console.log("1->3->2: " + (AC + BC));
- } else if ((AB + BC) > (AB + AC)){
- console.log("2->1->3: " + (AB + AC))
- }
- function distance(x1,y1,x2,y2){
- let distance = Math.sqrt(Math.pow((x2-x1),2) + Math.pow((y2-y1),2));
- return distance;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement