2.3 KiB
2.3 KiB
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
587d7da9367417b2b2512b66 | Combine Two Arrays Using the concat Method | 1 | Combine duas matrizes usando o método concat |
Description
Concatenation
significa unir itens de ponta a ponta. O JavaScript oferece o método concat
para cadeias de caracteres e matrizes que funcionam da mesma maneira. Para matrizes, o método é chamado em um, em seguida, outro array é fornecido como o argumento para concat
, que é adicionado ao final do primeiro array. Ele retorna um novo array e não altera os arrays originais. Aqui está um exemplo: [1, 2, 3] .concat ([4, 5, 6]);
// Retorna uma nova matriz [1, 2, 3, 4, 5, 6]
Instructions
concat
na função nonMutatingConcat
para concatenar attach
ao final do original
. A função deve retornar o array concatenado. Tests
tests:
- text: Seu código deve usar o método <code>concat</code> .
testString: 'assert(code.match(/\.concat/g), "Your code should use the <code>concat</code> method.");'
- text: O <code>first</code> array não deve mudar.
testString: 'assert(JSON.stringify(first) === JSON.stringify([1, 2, 3]), "The <code>first</code> array should not change.");'
- text: O <code>second</code> array não deve mudar.
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> deve retornar <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