Centroid of a set of N-dimensional points: Difference between revisions
Centroid of a set of N-dimensional points (view source)
Revision as of 08:39, 17 July 2023
, 11 months ago→{{header|Wren}}: Added some validity checks.
m (→{{header|Julia}}: err handling) |
(→{{header|Wren}}: Added some validity checks.) |
||
Line 85:
<syntaxhighlight lang="ecmascript">var centroid = Fn.new { |pts|
var n = pts.count
if (n == 0) Fiber.abort("List must contain at least one point.")
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)
for (j in 0...d) {
|