--- id: 587d7da9367417b2b2512b66 title: Combine Two Arrays Using the concat Method challengeType: 1 videoUrl: '' localeTitle: 使用concat方法组合两个数组 --- ## Description
Concatenation意味着端到端地连接项目。 JavaScript为字符串和数组提供了以相同方式工作的concat方法。对于数组,该方法在一个上调用,然后另一个数组作为concat的参数提供,该数组被添加到第一个数组的末尾。它返回一个新数组,不会改变任何一个原始数组。这是一个例子:
[1,2,3] .concat([4,5,6]);
//返回一个新数组[1,2,3,4,5,6]
## Instructions
使用nonMutatingConcat函数中的concat方法attachoriginal的结尾。该函数应返回连接数组。
## Tests
```yml tests: - text: 您的代码应使用concat方法。 testString: assert(code.match(/\.concat/g)); - text: 第first数组不应该改变。 testString: assert(JSON.stringify(first) === JSON.stringify([1, 2, 3])); - text: second数组不应该改变。 testString: assert(JSON.stringify(second) === JSON.stringify([4, 5])); - text: 'nonMutatingConcat([1, 2, 3], [4, 5])应该返回[1, 2, 3, 4, 5] 。' testString: assert(JSON.stringify(nonMutatingConcat([1, 2, 3], [4, 5])) === JSON.stringify([1, 2, 3, 4, 5])); ```
## Challenge Seed
```js 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
```js // solution required ```