Coding task · JavaScript and TypeScript course · Module 2: Functions, Arrays and Objects

Practice: Advanced Spread and Rest Patterns

Removing properties from an object, creating a copy with modification, rest in destructuring

Task

You have an object const dino = { name: 'Rex', health: 100, _secret: 'code', _internal: true }. Using destructuring with the rest operator, create a new object publicData without the _secret and _internal fields (dino must stay unchanged). Write a function updateDino(dino, updates) that returns a new object: a copy of dino overridden with the fields from updates, without changing the object passed in.