Files
freeCodeCamp/curriculum/challenges/chinese/10-coding-interview-prep/rosetta-code/deepcopy.md
Oliver Eyton-Williams ee1e8abd87 feat(curriculum): restore seed + solution to Chinese (#40683)
* feat(tools): add seed/solution restore script

* chore(curriculum): remove empty sections' markers

* chore(curriculum): add seed + solution to Chinese

* chore: remove old formatter

* fix: update getChallenges

parse translated challenges separately, without reference to the source

* chore(curriculum): add dashedName to English

* chore(curriculum): add dashedName to Chinese

* refactor: remove unused challenge property 'name'

* fix: relax dashedName requirement

* fix: stray tag

Remove stray `pre` tag from challenge file.

Signed-off-by: nhcarrigan <nhcarrigan@gmail.com>

Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
2021-01-12 19:31:00 -07:00

85 lines
1.2 KiB
Markdown

---
id: 596a8888ab7c01048de257d5
title: deepcopy的
challengeType: 5
videoUrl: ''
dashedName: deepcopy
---
# --description--
任务:
编写一个返回给定对象的深层副本的函数。
副本不得与给定的对象相同。
此任务不会测试:
具有属性属性的对象Date对象或具有Date对象属性的对象RegEx或具有RegEx对象属性的对象原型复制
# --hints--
`deepcopy`应该是一个功能。
```js
assert(typeof deepcopy === 'function');
```
`deepcopy({test: "test"})`应返回一个对象。
```js
assert(typeof deepcopy(obj1) === 'object');
```
不应该返回提供的相同对象。
```js
assert(deepcopy(obj2) != obj2);
```
传递包含数组的对象时,应返回该对象的深层副本。
```js
assert.deepEqual(deepcopy(obj2), obj2);
```
传递包含另一个对象的对象时,应返回该对象的深层副本。
```js
assert.deepEqual(deepcopy(obj3), obj3);
```
# --seed--
## --after-user-code--
```js
const obj1 = { test: 'test' };
const obj2 = {
t: 'test',
a: ['an', 'array']
};
const obj3 = {
t: 'try',
o: obj2
};
```
## --seed-contents--
```js
function deepcopy(obj) {
return true;
}
```
# --solutions--
```js
function deepcopy(obj) {
return JSON.parse(JSON.stringify(obj));
}
```