--description--
Concatenation means to join items end to end. JavaScript offers the 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:
[1, 2, 3].concat([4, 5, 6]);
The returned array would be [1, 2, 3, 4, 5, 6]
.
--instructions--
Use the concat
method in the nonMutatingConcat
function to concatenate attach
to the end of original
. The function should return the concatenated array.
--hints--
Your code should use the concat
method.
assert(__helpers.removeJSComments(code).match(/\.concat/g));
The first
array should not change.
assert(JSON.stringify(first) === JSON.stringify([1, 2, 3]));
The second
array should not change.
assert(JSON.stringify(second) === JSON.stringify([4, 5]));
nonMutatingConcat([1, 2, 3], [4, 5])
should return [1, 2, 3, 4, 5]
.
assert(
JSON.stringify(nonMutatingConcat([1, 2, 3], [4, 5])) ===
JSON.stringify([1, 2, 3, 4, 5])
);
--seed--
--seed-contents--
function nonMutatingConcat(original, attach) {
// Only change code below this line
// Only change code above this line
}
const first = [1, 2, 3];
const second = [4, 5];
nonMutatingConcat(first, second);
--solutions--
function nonMutatingConcat(original, attach) {
return original.concat(attach);
}
const first = [1, 2, 3];
const second = [4, 5];