Practice cloning and navigating objects

In this exercise, we are going to practice cloning an object and updating it.

It all begins with John’s Amazon order:

const johnsOrder = {
    orderId: 123456,
    customer: {
        customerId: 789,
        name: 'John Doe',
        address: {
            street: '123 Main St',
            city: 'New York',
            country: 'USA',
        },
    },
    items: [
        { id: '1', name: 'Product A', price: 10 },
        { id: '2', name: 'Product B', price: 20 },
    ],
};

John has a wife called Jane.

Jane decides to also place an order. Here are the details:

Order Id: 6335

Customer Id: 456

Product Item Id: 3

Product Item Name: “Product C”

Product Price: 999

The task

Create a new order object for Jane based on John’s original order.

Since John and Jane share the same address, we want to keep those values. But we also don’t want to mutate John’s order, or have any shared objects/arrays between the two orders.

Write the code that results in Jane’s order object.

Links & Resources