concat
method for both strings and arrays that work in the same way. For arrays, the method is called on one, then another array is provided as the argument to concat
, which is added to the end of the first array. It returns a new array and does not mutate either of the original arrays. Here's an example:
```js
[1, 2, 3].concat([4, 5, 6]);
// Returns a new array [1, 2, 3, 4, 5, 6]
```
concat
method in the nonMutatingConcat
function to concatenate attach
to the end of original
. The function should return the concatenated array.
concat
method.
testString: assert(code.match(/\.concat/g));
- text: The first
array should not change.
testString: assert(JSON.stringify(first) === JSON.stringify([1, 2, 3]));
- text: The second
array should not change.
testString: assert(JSON.stringify(second) === JSON.stringify([4, 5]));
- text: nonMutatingConcat([1, 2, 3], [4, 5])
should return [1, 2, 3, 4, 5]
.
testString: assert(JSON.stringify(nonMutatingConcat([1, 2, 3], [4, 5])) === JSON.stringify([1, 2, 3, 4, 5]));
```