(values, p)
| 200 | } |
| 201 | |
| 202 | function percentile(values, p) { |
| 203 | if (values.length === 0) return 0 |
| 204 | const sorted = [...values].sort((a, b) => a - b) |
| 205 | const index = Math.min(sorted.length - 1, Math.max(0, Math.ceil((p / 100) * sorted.length) - 1)) |
| 206 | return sorted[index] |
| 207 | } |
| 208 | |
| 209 | function round(value) { |
| 210 | return Math.round(value * 100) / 100 |