{"ScriptPreparationCode":"const {\r\n PI,\r\n sqrt,\r\n cos,\r\n sin,\r\n asin,\r\n pow,\r\n atan2,\r\n random\r\n} = Math\r\n\r\nfunction toRadians(angle) {\r\n return PI * angle / 180\r\n}\r\n\r\nfunction Haversine(point1, point2) {\r\n const r = 6373\r\n const latOrigem = toRadians(point1.latitude)\r\n const lonOrigem = toRadians(point1.longitude)\r\n const latDistino = toRadians(point2.latitude)\r\n const lonDistino = toRadians(point2.longitude)\r\n const a = pow(\r\n sin((latDistino - latOrigem) / 2), 2) \u002B cos(latOrigem) *\r\n cos(latDistino) * pow(sin((lonDistino - lonOrigem) / 2), 2)\r\n const c = 2 * atan2(sqrt(a), sqrt(1 - a))\r\n return c * r\r\n}\r\n\r\nfunction Haversine2(point1, point2) {\r\n const R = 6373\r\n const dLat = toRadians(point2.latitude - point1.latitude)\r\n const dLon = toRadians(point2.longitude - point1.longitude)\r\n const ht =\r\n 0.5 - cos(dLat) / 2 \u002B\r\n cos(toRadians(point1.latitude)) * cos(toRadians(point2.latitude)) *\r\n (1 - cos(dLon)) / 2\r\n\r\n return R * 2 * asin(sqrt(ht))\r\n}\r\n\r\nfunction Haversine3(point1, point2) {\r\n const R = 6373\r\n const ph1 = toRadians(point1.longitude - point2.longitude)\r\n const th1 = toRadians(point1.latitude)\r\n const th2 = toRadians(point2.latitude)\r\n const cth1 = cos(th1)\r\n const dz = sin(th1) - sin(th2)\r\n const dx = cos(ph1) * cth1 - cos(th2)\r\n const dy = sin(ph1) * cth1\r\n return 2 * R * asin(sqrt(dx * dx \u002B dy * dy \u002B dz * dz) / 2)\r\n}\r\n\r\nfunction getRandomLat() {\r\n return random() * (90 \u002B 90 \u002B 1) - 90\r\n}\r\n\r\nfunction getRandomLon() {\r\n return Math.random() * (180 \u002B 180 \u002B 1) - 180\r\n}\r\n\r\nfunction getRandomPoints(n) {\r\n return new Array(n).map(() =\u003E {\r\n const point1 = {\r\n latitude: getRandomLat(),\r\n longitude: getRandomLon()\r\n }\r\n\r\n const point2 = {\r\n latitude: getRandomLat(),\r\n longitude: getRandomLon()\r\n }\r\n })\r\n}\r\n\r\nvar points = getRandomPoints(100)","TestCases":[{"Name":"1","Code":"points.forEach(() =\u003E Haversine(p1, p2))","IsDeferred":false},{"Name":"2","Code":"points.forEach(() =\u003E Haversine2(p1, p2))","IsDeferred":false},{"Name":"3","Code":"points.forEach(() =\u003E Haversine3(p1, p2))","IsDeferred":false}]}