2021-02-06 04:42:36 +00:00
---
id: 587d7da9367417b2b2512b66
2021-03-17 13:48:12 -06:00
title: Combina dos arreglos utilizando el método "concat"
2021-02-06 04:42:36 +00:00
challengeType: 1
forumTopicId: 301229
dashedName: combine-two-arrays-using-the-concat-method
---
# --description--
2021-03-17 13:48:12 -06:00
< dfn > Concatenation</ dfn > significa unir elementos de extremo a extremo. JavaScript ofrece el método `concat` para cadenas y arreglos, que funciona de la misma manera. Para arreglos, el método es llamado desde un arreglo, un segundo arrelgo es proporcionado como argumento de `concat` , este se añadirá al final del primer arreglo. Devuelve un nuevo arreglo, sin mutar ninguno de los arreglos originales. Aquí hay un ejemplo:
2021-02-06 04:42:36 +00:00
```js
[1, 2, 3].concat([4, 5, 6]);
```
2021-03-17 13:48:12 -06:00
El arreglo devuelto sería `[1, 2, 3, 4, 5, 6]` .
2021-02-06 04:42:36 +00:00
# --instructions--
2021-03-17 13:48:12 -06:00
Usa el método `concat` en la función `nonMutatingConcat` para concatenar `attach` al final de `original` . La función deber devolver el arreglo concatenado.
2021-02-06 04:42:36 +00:00
# --hints--
2021-03-17 13:48:12 -06:00
Tu código debe usar el método `concat` .
2021-02-06 04:42:36 +00:00
```js
assert(code.match(/\.concat/g));
```
2021-03-17 13:48:12 -06:00
El arreglo `first` no debe cambiar.
2021-02-06 04:42:36 +00:00
```js
assert(JSON.stringify(first) === JSON.stringify([1, 2, 3]));
```
2021-03-17 13:48:12 -06:00
El arreglo `second` no debe cambiar.
2021-02-06 04:42:36 +00:00
```js
assert(JSON.stringify(second) === JSON.stringify([4, 5]));
```
2021-03-17 13:48:12 -06:00
`nonMutatingConcat([1, 2, 3], [4, 5])` debe devolver `[1, 2, 3, 4, 5]` .
2021-02-06 04:42:36 +00:00
```js
assert(
JSON.stringify(nonMutatingConcat([1, 2, 3], [4, 5])) ===
JSON.stringify([1, 2, 3, 4, 5])
);
```
# --seed--
## --seed-contents--
```js
function nonMutatingConcat(original, attach) {
// Only change code below this line
// Only change code above this line
}
2021-10-27 15:10:57 +00:00
const first = [1, 2, 3];
const second = [4, 5];
2021-02-06 04:42:36 +00:00
nonMutatingConcat(first, second);
```
# --solutions--
```js
function nonMutatingConcat(original, attach) {
return original.concat(attach);
}
2021-10-27 15:10:57 +00:00
const first = [1, 2, 3];
const second = [4, 5];
2021-02-06 04:42:36 +00:00
```