Concatenation significa unir artículos de extremo a extremo. JavaScript ofrece el método concat para cadenas y matrices que funcionan de la misma manera. Para las matrices, el método se llama en una, luego se proporciona otra matriz como el argumento a concat , que se agrega al final de la primera matriz. Devuelve una nueva matriz y no muta ninguna de las matrices originales. Aquí hay un ejemplo: [1, 2, 3] .concat ([4, 5, 6]);
// Devuelve una nueva matriz [1, 2, 3, 4, 5, 6]
concat en la función nonMutatingConcat para concatenar attach al final del original . La función debe devolver la matriz concatenada. concat .
testString: 'assert(code.match(/\.concat/g), "Your code should use the concat 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: 'nonMutatingConcat([1, 2, 3], [4, 5]) debe devolver [1, 2, 3, 4, 5] .'
testString: 'assert(JSON.stringify(nonMutatingConcat([1, 2, 3], [4, 5])) === JSON.stringify([1, 2, 3, 4, 5]), "nonMutatingConcat([1, 2, 3], [4, 5]) should return [1, 2, 3, 4, 5].");'
```