← Back to challenges

Area of a Polygon

JavaScriptHardalgebraalgorithmsmathtrigonometry

Instructions

Given a unordered array of the vertices of a convex polygon, find its area.

Examples

polygon([[2, 5], [5, 1], [-4, 3]]) ➞ 15.0

polygon([[-1, 1], [1, 1], [-1, -1], [1, -1]]) ➞ 4.0

polygon([[2, 2], [11, 2], [4, 10], [9, 7]]) ➞ 45.5

polygon([[5, 3], [3, 4], [12, 8], [5, 11], [9, 5]]) ➞ 39.0

Notes

  • A convex polygon has all interior angles less than 180 degrees.
  • The first example has only 3 vertices so this list is ordered by default.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.