freeCodeCamp/curriculum/challenges/chinese/08-coding-interview-prep/rosetta-code/deepcopy.chinese.md

1.8 KiB

title id challengeType videoUrl localeTitle
Deepcopy 596a8888ab7c01048de257d5 5 deepcopy的

Description

任务:

编写一个返回给定对象的深层副本的函数。

副本不得与给定的对象相同。

此任务不会测试:

具有属性属性的对象Date对象或具有Date对象属性的对象RegEx或具有RegEx对象属性的对象原型复制

Instructions

Tests

tests:
  - text: <code>deepcopy</code>应该是一个功能。
    testString: 'assert(typeof deepcopy === "function", "<code>deepcopy</code> should be a function.");'
  - text: '<code>deepcopy({test: &quot;test&quot;})</code>应返回一个对象。'
    testString: 'assert(typeof deepcopy(obj1) === "object", "<code>deepcopy({test: "test"})</code> should return an object.");'
  - text: 不应该返回提供的相同对象。
    testString: 'assert(deepcopy(obj2) != obj2, "Should not return the same object that was provided.");'
  - text: 传递包含数组的对象时,应返回该对象的深层副本。
    testString: 'assert.deepEqual(deepcopy(obj2), obj2, "When passed an object containing an array, should return a deep copy of the object.");'
  - text: 传递包含另一个对象的对象时,应返回该对象的深层副本。
    testString: 'assert.deepEqual(deepcopy(obj3), obj3, "When passed an object containing another object, should return a deep copy of the object.");'

Challenge Seed

function deepcopy (obj) {
  // Good luck!
  return true;
}

After Test

console.info('after the test');

Solution

// solution required