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]
concat
na função nonMutatingConcat
para concatenar attach
ao final do original
. A função deve retornar o array concatenado. concat
.
testString: 'assert(code.match(/\.concat/g), "Your code should use the concat
method.");'
- text: O first
array não deve mudar.
testString: 'assert(JSON.stringify(first) === JSON.stringify([1, 2, 3]), "The first
array should not change.");'
- text: O second
array não deve mudar.
testString: 'assert(JSON.stringify(second) === JSON.stringify([4, 5]), "The second
array should not change.");'
- text: 'nonMutatingConcat([1, 2, 3], [4, 5])
deve retornar [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]
.");'
```