(buf)
| 872 | } |
| 873 | |
| 874 | function median(buf) { |
| 875 | if (buf.length === 0) return 0; |
| 876 | const a = [...buf].sort((x, y) => x - y); |
| 877 | const mid = Math.floor(a.length / 2); |
| 878 | return a.length % 2 ? a[mid] : (a[mid - 1] + a[mid]) * 0.5; |
| 879 | } |
| 880 | |
| 881 | function centroid(points) { |
| 882 | let x = 0, |