JavaScript practice question based on haversine formula