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

Practice: Spread and Rest - Arrays and Objects

Practice copying arrays, merging objects, and rest in functions

Task

You have the arrays const carnivores = ['T-Rex', 'Velociraptor'] and const herbivores = ['Triceratops'] and the object const defaults = { zone: 'A', locked: true }. Using the spread operator, create: allDinos (both arrays merged), carnivoresCopy (a new copy of carnivores) and config (defaults overridden with zone: 'B'). Also write a function countSightings(observer, ...dinos) that returns the number of dinosaurs passed.