Concatenation
意味着端到端地连接项目。 JavaScript为字符串和数组提供了以相同方式工作的concat
方法。对于数组,该方法在一个上调用,然后另一个数组作为concat
的参数提供,该数组被添加到第一个数组的末尾。它返回一个新数组,不会改变任何一个原始数组。这是一个例子: [1,2,3] .concat([4,5,6]);
//返回一个新数组[1,2,3,4,5,6]
nonMutatingConcat
函数中的concat
方法attach
到original
的结尾。该函数应返回连接数组。 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]));
```