Advertisement
xapu

Untitled

May 27th, 2017
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. function demo(input){
  2. let [x1,y1,x2,y2,x3,y3] = input.map(Number)
  3.  
  4. let istanceBetweenTwoPoints = (x1,y1,x2,y2)=> Math.sqrt(Math.pow((x2-x1),2)+Math.pow((y2-y1),2))
  5.  
  6. let distance123 = istanceBetweenTwoPoints(x1,y1,x2,y2)+istanceBetweenTwoPoints(x2,y2,x3,y3)
  7. let distance132 = istanceBetweenTwoPoints(x1,y1,x3,y3)+istanceBetweenTwoPoints(x2,y2,x3,y3)
  8. let distance213 = istanceBetweenTwoPoints(x1,y1,x2,y2)+istanceBetweenTwoPoints(x1,y1,x3,y3)
  9.  
  10. let shorrt = Math.min(distance123,distance132,distance213)
  11.  
  12.  
  13.  
  14. if(shorrt == distance123){
  15. console.log("1->2->3: "+shorrt)
  16. }else if(shorrt == distance132){
  17. console.log("1->3->2: "+shorrt)
  18. }else{
  19. console.log("2->1->3: "+shorrt)
  20. }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement