concat como uma maneira de combinar matrizes em um novo sem alterar os arrays originais. Compare concat no método push . Push adiciona um item ao final do mesmo array em que é chamado, o que modifica esse array. Aqui está um exemplo: var arr = [1, 2, 3];
arr.push ([4, 5, 6]);
// arr é alterado para [1, 2, 3, [4, 5, 6]]
// Não é a maneira funcional de programação
Concat oferece uma maneira de adicionar novos itens ao final de um array sem nenhum efeito colateral mutante. nonMutatingPush para que use a concat para adicionar newItem ao final do original vez de push . A função deve retornar uma matriz. concat .
testString: 'assert(code.match(/\.concat/g), "Your code should use the concat method.");'
- text: Seu código não deve usar o método push .
testString: 'assert(!code.match(/\.push/g), "Your code should not use the push 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: 'nonMutatingPush([1, 2, 3], [4, 5]) deve retornar [1, 2, 3, 4, 5] .'
testString: 'assert(JSON.stringify(nonMutatingPush([1, 2, 3], [4, 5])) === JSON.stringify([1, 2, 3, 4, 5]), "nonMutatingPush([1, 2, 3], [4, 5]) should return [1, 2, 3, 4, 5].");'
```