Coding task · JavaScript and TypeScript course · Module 2: Functions, Arrays and Objects
Practice: Advanced Destructuring
Nested destructuring, in function parameters, and with the rest operator
Task
You have a report: const report = { id: 'R-7', dino: { name: 'Blue', vitals: { heartRate: 65, temperature: 37.2 } }, zone: 'B', status: 'ok' }. Using destructuring, create: id, patientName (an alias for report.dino.name), heartRate (from report.dino.vitals) and an object meta that collects the remaining top-level properties (without id and dino) with the rest operator. Also write a function formatVitals({ heartRate, temperature = 36.6 }) that returns the text heartRate + ' bpm, ' + temperature + ' C'.