mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-04-12 10:00:39 -04:00
1.5 KiB
1.5 KiB
id, title, challengeType, forumTopicId, dashedName
| id | title | challengeType | forumTopicId | dashedName |
|---|---|---|---|---|
| 596a8888ab7c01048de257d5 | Deepcopy | 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.
Questa sfida non testa per:
- Objects with properties that are functions
- Oggetti Date o oggetti con proprietà che sono oggetti Date
- RegEx o oggetti con proprietà che sono RegEx
- Copiamento del prototype
--hints--
deepcopy dovrebbe essere una funzione.
assert(typeof deepcopy === 'function');
deepcopy({test: "test"}) dovrebbe restituire un oggetto.
assert(typeof deepcopy(obj1) === 'object');
deepcopy non dovrebbe restituire lo stesso oggetto dato.
assert(deepcopy(obj2) != obj2);
Quando gli viene dato un oggetto contenente un array, deepcopy dovrebbe restituire una copia profonda dell'oggetto.
assert.deepEqual(deepcopy(obj2), obj2);
Quando gli viene dato un oggetto contenente un altro oggetto, deepcopy dovrebbe restituire una copia profonda dell'oggetto.
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));
}