mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-04-12 19:00:43 -04:00
1.7 KiB
1.7 KiB
id, title, challengeType, forumTopicId, dashedName
| id | title | challengeType | forumTopicId | dashedName |
|---|---|---|---|---|
| 596a8888ab7c01048de257d5 | ディープコピー | 1 | 302247 | deepcopy |
--description--
Write a function that returns a deep copy of a given object. The copy must not be the same object that was given.
このタスクは次のものをテストするものではありません。
- Objects with properties that are functions
- 日付オブジェクト、または日付オブジェクトであるプロパティを持つオブジェクト
- RegEx、またはRegExオブジェクトであるプロパティを持つオブジェクト
- プロトタイプのコピー
--hints--
deepcopy という関数です。
assert(typeof deepcopy === 'function');
deepcopy({test: "test"}) はオブジェクトを返します。
assert(typeof deepcopy(obj1) === 'object');
deepcopy は元のオブジェクトと同じオブジェクトを返しません。
assert(deepcopy(obj2) != obj2);
配列を含むオブジェクトが渡された場合、 deepcopy はそのオブジェクトのディープコピーを返します。
assert.deepEqual(deepcopy(obj2), obj2);
別のオブジェクトを含むオブジェクトが渡された場合、 deepcopy はそのオブジェクトのディープコピーを返します。
assert.deepEqual(deepcopy(obj3), obj3);
--seed--
--after-user-code--
const obj1 = { test: 'test' };
const obj2 = {
t: 'test',
a: ['an', 'array']
};
const obj3 = {
t: 'try',
o: obj2
};
--seed-contents--
function deepcopy(obj) {
return true;
}
--solutions--
function deepcopy(obj) {
return JSON.parse(JSON.stringify(obj));
}