Latihan 1 dari materi Debugging Production Incidents di Debugging — praktek dengan editor kode interaktif, test case otomatis, dan hint terpandu. Langsung jalan di browser.
Buat dua function untuk analisis incident production:
1. analyzeErrorRate(events, windowMs)
events: array of { type: "error" | "success", timestamp } (timestamp dalam ms)windowMs: window waktu dalam ms (default 60000)windowMs terakhir dari event terbaru{ errorRate, total, errors }:
errorRate: persentase error (0-100, dibulatkan ke integer)total: jumlah semua event dalam windowerrors: jumlah event error2. detectAnomalies(rates)
rates: array of numbers (error rate per menit){ index, rate, isAnomaly } — isAnomaly: true jika rate > 2x rata-rata