| Conditions | 4 |
| Paths | 6 |
| Total Lines | 15 |
| Code Lines | 7 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 22 | function find_centroid(array $points): array |
||
| 23 | { |
||
| 24 | $centroid = []; |
||
| 25 | |||
| 26 | foreach ($points as $point) { |
||
| 27 | foreach ($point as $n => $value) { |
||
| 28 | $centroid[$n] = ($centroid[$n] ?? 0) + $value; |
||
| 29 | } |
||
| 30 | } |
||
| 31 | |||
| 32 | foreach ($centroid as &$value) { |
||
| 33 | $value /= count($points); |
||
| 34 | } |
||
| 35 | |||
| 36 | return $centroid; |
||
| 37 | } |
||
| 64 |
If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration: