Files
lynchmark/tests/2_convex_hull/outputs/anthropic_claude-sonnet-4.6.js
2026-02-17 22:10:27 +00:00

26 lines
751 B
JavaScript

async function findConvexHull(points) {
const { default: _ } = await import("https://cdn.skypack.dev/lodash");
const unique = _.uniqWith(points, _.isEqual);
const sorted = _.sortBy(unique, ["x", "y"]);
if (sorted.length < 3) return sorted;
const cross = (o, a, b) =>
(a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
const buildHalf = (pts) =>
pts.reduce((hull, p) => {
while (hull.length >= 2 && cross(hull.at(-2), hull.at(-1), p) <= 0)
hull.pop();
return [...hull, p];
}, []);
const lower = buildHalf(sorted);
const upper = buildHalf([...sorted].reverse());
return [...lower.slice(0, -1), ...upper.slice(0, -1)];
}
export default findConvexHull;
// Generation time: 3.848s
// Result: PASS