| Folder Name | Branch | Coefficient |
|---|---|---|
| /deep-copy | deep-copy | 0.5 |
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.
...), structuredClone, JSON.stringify, JSON.parse, or any npm libraries.null or undefined.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
index.js file in the deep-copy folder must export the copy function as follows:function copy(obj) {}
module.exports = { copy };
Your Pull Request must include:
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.
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 |
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.
=) to copy an object in JavaScript?Object.assign copy, and why is it not sufficient for a deep copy?Array, a Date, a plain Object, null, and a function at runtime in JavaScript?typeof null === 'object' and how does your code handle that edge case?instanceof work, and when might it give unexpected results?Date objects be copied differently from plain objects?Object.getOwnPropertyDescriptor, Object.defineProperty)?copy handle?Object.getOwnPropertyNames return vs. for...in?copy replicate it? Why or why not?