Shoelace formula for polygonal area: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(One intermediate revision by one other user not shown)
Line 624:
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,476

edits