What's the 75th percentile of these samples?
Eight visits to the tea page sent their LCP. The code takes the 75th percentile with the nearest-rank rule, puts the mean beside it, rates both against LCP's thresholds, and counts the good visits. What does it log?
// The LCP of eight visits to Leaf and Kettle's tea page, in milliseconds, in the order they came in.
const lcp = [2900, 1100, 1300, 3100, 900, 1200, 2700, 1000];
const rating = (ms) => (ms > 4000 ? "poor" : ms > 2500 ? "needs-improvement" : "good");
// Nearest rank: sort from fastest to slowest, then take the visit at place ceil(0.75 × n), counting from 1.
const sorted = [...lcp].sort((a, b) => a - b);
const place = Math.ceil(0.75 * sorted.length);
const p75 = sorted[place - 1];
const mean = lcp.reduce((sum, ms) => sum + ms, 0) / lcp.length;
const good = lcp.filter((ms) => ms <= 2500).length;
console.log("Sorted: " + sorted.join(", "));
console.log(`p75 is visit ${place} of ${sorted.length}: ${p75} ms (${rating(p75)})`);
console.log(`Mean: ${mean} ms (${rating(mean)})`);
console.log(`Good visits: ${good} of ${lcp.length}`);
Practice it in the editor, with tests
The answer
Work out every line it logs, in order. Then check.
Checking your sign-in…