able to sort the paths according distance in array