| 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:
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 PR includes more than one required index.js file |
-50 |
The solution includes rest/spread operators (...), structuredClone, JSON.stringify, JSON.parse, or any npm libraries. |
-100 |