added distance function to javascript