Area of a polygon with given n ordered vertices | ( X [ i ] , Y [ i ] ) are coordinates of i 'th point. ; Initialize area ; Calculate value of shoelace formula ; j is previous vertex to i ; Return absolute value ; Driver Code
function polygonArea ( X , Y , n ) { let area = 0.0 ; let j = n - 1 ; for ( let i = 0 ; i < n ; i ++ ) { area += ( X [ j ] + X [ i ] ) * ( Y [ j ] - Y [ i ] ) ; j = i ; } return Math . abs ( area / 2.0 ) ; } let X = [ 0 , 2 , 4 ] ; let Y = [ 1 , 3 , 7 ] ; let n = 3 ; document . write ( polygonArea ( X , Y , n ) ) ;