2.3 KiB
2.3 KiB
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
587d7da9367417b2b2512b66 | Combine Two Arrays Using the concat Method | 1 | Combina dos matrices usando el método concat |
Description
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]
Instructions
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