freeCodeCamp/curriculum/challenges/spanish/02-javascript-algorithms-an.../functional-programming/combine-two-arrays-using-th...

2.3 KiB

id title localeTitle challengeType
587d7da9367417b2b2512b66 Combine Two Arrays Using the concat Method Combina dos matrices usando el método concat 1

Description

Concatenation significa unir elementos 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]);
// Returns a new array [1, 2, 3, 4, 5, 6]

Instructions

Utilice el método concat en la función nonMutatingConcat para concatenar attach al final del original . La función debe devolver la matriz concatenada.

Tests

tests:
  - text: Su código debe utilizar el método <code>concat</code> .
    testString: 'assert(code.match(/\.concat/g), "Your code should use the <code>concat</code> method.");'
  - text: La <code>first</code> matriz no debe cambiar.
    testString: 'assert(JSON.stringify(first) === JSON.stringify([1, 2, 3]), "The <code>first</code> array should not change.");'
  - text: La <code>second</code> matriz no debe cambiar.
    testString: 'assert(JSON.stringify(second) === JSON.stringify([4, 5]), "The <code>second</code> array should not change.");'
  - text: ' <code>nonMutatingConcat([1, 2, 3], [4, 5])</code> debe devolver <code>[1, 2, 3, 4, 5]</code> .'
    testString: 'assert(JSON.stringify(nonMutatingConcat([1, 2, 3], [4, 5])) === JSON.stringify([1, 2, 3, 4, 5]), "<code>nonMutatingConcat([1, 2, 3], [4, 5])</code> should return <code>[1, 2, 3, 4, 5]</code>.");'

Challenge Seed

function nonMutatingConcat(original, attach) {
  // Add your code below this line


  // Add your code above this line
}
var first = [1, 2, 3];
var second = [4, 5];
nonMutatingConcat(first, second);

Solution

// solution required