--- id: 587d7da9367417b2b2512b67 title: Add Elements to the End of an Array Using concat Instead of push challengeType: 1 videoUrl: '' localeTitle: Agregue elementos al final de una matriz usando concat en lugar de empujar --- ## Description
La programación funcional tiene que ver con la creación y el uso de funciones no mutantes. El último desafío introdujo el método concat como una forma de combinar arreglos en uno nuevo sin mutar los arreglos originales. Comparar concat con el método de push . Push agrega un elemento al final de la misma matriz a la que se llama, lo que muta esa matriz. Aquí hay un ejemplo:
var arr = [1, 2, 3];
arr.push ([4, 5, 6]);
// arr se cambia a [1, 2, 3, [4, 5, 6]]
// No es la forma de programación funcional
Concat ofrece una forma de agregar nuevos elementos al final de una matriz sin efectos secundarios mutantes.
## Instructions
Cambie la función nonMutatingPush para que use concat para agregar newItem al final del original en lugar de push . La función debe devolver una matriz.
## Tests
```yml tests: - text: Su código debe utilizar el método concat . testString: 'assert(code.match(/\.concat/g), "Your code should use the concat method.");' - text: Su código no debe utilizar el método de push . testString: 'assert(!code.match(/\.push/g), "Your code should not use the push method.");' - text: La first matriz no debe cambiar. testString: 'assert(JSON.stringify(first) === JSON.stringify([1, 2, 3]), "The first array should not change.");' - text: La second matriz no debe cambiar. testString: 'assert(JSON.stringify(second) === JSON.stringify([4, 5]), "The second array should not change.");' - text: 'nonMutatingPush([1, 2, 3], [4, 5]) debe devolver [1, 2, 3, 4, 5] .' testString: 'assert(JSON.stringify(nonMutatingPush([1, 2, 3], [4, 5])) === JSON.stringify([1, 2, 3, 4, 5]), "nonMutatingPush([1, 2, 3], [4, 5]) should return [1, 2, 3, 4, 5].");' ```
## Challenge Seed
```js function nonMutatingPush(original, newItem) { // Add your code below this line return original.push(newItem); // Add your code above this line } var first = [1, 2, 3]; var second = [4, 5]; nonMutatingPush(first, second); ```
## Solution
```js // solution required ```