Centroid of a set of N-dimensional points: Difference between revisions

Content added Content deleted
m (→‎{{header|Julia}}: err handling)
(→‎{{header|Wren}}: Added some validity checks.)
Line 85: Line 85:
<syntaxhighlight lang="ecmascript">var centroid = Fn.new { |pts|
<syntaxhighlight lang="ecmascript">var centroid = Fn.new { |pts|
var n = pts.count
var n = pts.count
if (n == 0) Fiber.abort("List must contain at least one point.")
var d = pts[0].count
var d = pts[0].count
if (pts.skip(1).any { |p| p.count != d }) {
Fiber.abort("Points must all have the same dimension.")
}
var res = List.filled(d, 0)
var res = List.filled(d, 0)
for (j in 0...d) {
for (j in 0...d) {