Shoelace formula for polygonal area: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
No edit summary
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(2 intermediate revisions by 2 users not shown)
Line 622:
.
data[][] = [ [ 3 4 ] [ 5 11 ] [ 12 8 ] [ 9 5 ] [ 5 6 ] ]
call shoelace data[][] res
print res
</syntaxhighlight>
 
=={{header|Elixir}}==
<syntaxhighlight lang="elixir">
def shoelace(points) do
points
|> Enum.reduce({0, List.last(points)}, fn {x1, y1}, {sum, {x0, y0}} ->
{sum + (y0 * x1 - x0 * y1), {x1, y1}}
end)
|> elem(0)
|> div(2)
end
</syntaxhighlight>
 
Line 2,107 ⟶ 2,119:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">var shoelace = Fn.new { |pts|
var area = 0
for (i in 0...pts.count-1) {
9,482

edits