epam-short-track

Task 3. Deep-copy

Folder Name Branch Coefficient
/deep-copy deep-copy 0.5

Task Description

Implement a custom copy function that creates a deep copy of a given object. Your implementation must handle all types listed below, support any level of nesting, and strictly follow the requirements.

Requirements

Example

const complexObject = {
  stringValue: "Hello, World!",
  numberValue: 42,
  booleanValue: true,
  nullValue: null,
  undefinedValue: undefined,
  bigIntValue: BigInt(9007199254740991),
  arrayValue: [1, 2, 3, "four", { nestedKey: "nestedValue" }],
  valueDate: new Date(),
  nestedObject: {
    level1: {
      level2: {
        level3: {
          stringValue: "Deep Nesting",
          numberValue: 3.14,
          booleanValue: false,
          arrayValue: [true, false, null],
          anotherNestedObject: {
            level4: "Final Level",
            functionValue: function() {
              return "I am a function!";
            }
          }
        }
      }
    }
  },
  functionValue: function() {
    return "I am a function!";
  }
};

const obj1 = copy(complexObject);

console.log(obj1 === complexObject); // false
console.log(obj1.nestedObject.level1.level2.level3 === complexObject.nestedObject.level1.level2.level3); // false
console.log(obj1.arrayValue === complexObject.arrayValue); // false

Implementation Details

function copy(obj) {}

module.exports = { copy };

Pull Request Requirements

Your Pull Request must include:


Developer’s Diary

While working on this task, keep a developer’s diary. Write down the decisions you made, the approaches you considered, where you got stuck, and how you worked through it.

The diary is not graded. Its purpose is to help you understand your own work more deeply and to give your mentor a basis for a real conversation about the task.

The “Diary” folder can be placed in the root of the project.


Mentor Checklist

Maximum Score: 100 points

Criteria Points
The branch is named deep-copy 2
Commit messages follow RS School Git Convention 5
The deep-copy folder exists 2
The index.js file exists in the correct folder 2
The index.js file exports the copy function 1
The function correctly deep-copies the following types:  
    String 5
    Number 5
    Boolean 5
    Null 5
    Undefined 5
    BigInt 5
    Date 8
    Function 8
    Array 8
    Object 8
    get/set accessors 8
The solution is well-structured, readable, and follows best practices 10
   
Pull Request description includes all required elements:  
Task URL is included in the PR 2
Description of test objects and types is included in the PR 2
Submission and Deadline Dates are included in the PR 2
Your self-check of the task’s completion using checkboxes is included in the PR 2
   
Penalty:  
Less than 3 commits in the PR -20
Commit after the deadline and before mentor review -20
The solution includes any comments -50
The solution includes console.log -10
The solution includes rest/spread operators (...), structuredClone, JSON.stringify, JSON.parse, or any npm libraries. -100

Mentor Interview Topics

After submitting the task, your mentor will ask 4–5 questions from the areas below. Answers account for ~80 points of the total score, so make sure you can explain the concepts in your own words — not just recite a definition.

Deep copy vs. shallow copy

Recursion

Type detection and handling

Property descriptors and accessors

JavaScript object model


Notes