Files
freeCodeCamp/curriculum/challenges/spanish/08-coding-interview-prep/rosetta-code/deepcopy.spanish.md
2018-10-08 13:34:43 -04:00

2.1 KiB

title, id, localeTitle, challengeType
title id localeTitle challengeType
Deepcopy 596a8888ab7c01048de257d5 596a8888ab7c01048de257d5 5

Description

Tarea:

Escribe una función que devuelva una copia profunda de un objeto dado.

La copia no debe ser el mismo objeto que se le dio.

Esta tarea no probará para:

Objetos con propiedades que son funciones Objetos de fecha u objeto con propiedades que son objetos de fecha RegEx u objeto con propiedades que son objetos de RegEx Copia de prototipo

Instructions

Tests

tests:
  - text: <code>deepcopy</code> debe ser una función.
    testString: 'assert(typeof deepcopy === "function", "<code>deepcopy</code> should be a function.");'
  - text: &#39; <code>deepcopy({test: &quot;test&quot;})</code> debe devolver un objeto.&#39;
    testString: 'assert(typeof deepcopy(obj1) === "object", "<code>deepcopy({test: "test"})</code> should return an object.");'
  - text: No debe devolver el mismo objeto que se proporcionó.
    testString: 'assert(deepcopy(obj2) != obj2, "Should not return the same object that was provided.");'
  - text: &#39;Cuando se pasa un objeto que contiene una matriz, debe devolver una copia profunda del objeto&#39;.
    testString: 'assert.deepEqual(deepcopy(obj2), obj2, "When passed an object containing an array, should return a deep copy of the object.");'
  - text: &#39;Cuando se pasa un objeto que contiene otro objeto, debe devolver una copia profunda del objeto&#39;.
    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

function deepcopy(obj) {
  return JSON.parse(JSON.stringify(obj));
}