Combine Two Arrays Using the concat Method

Tell us what’s happening:

What i’m doing wrong?

Your code so far


function nonMutatingConcat(original, attach) {
  // Add your code below this line
nonMutatingConcat([1, 2, 3], [4, 5]);

  
  // Add your code above this line
}
var first = [1, 2, 3];
var second = [4, 5];
nonMutatingConcat(first, second);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/functional-programming/combine-two-arrays-using-the-concat-method

https://www.w3schools.com/jsref/jsref_concat_array.asp

original.concat(attached)

function nonMutatingConcat(original, attach) {
// Add your code below this line
[1, 2, 3].concat([4, 5, 6]);

// Add your code above this line
}
var first = [1, 2, 3];
var second = [4, 5];
nonMutatingConcat(first, second);

This is my new code but the exercise tell me that
nonMutatingConcat([1, 2, 3], [4, 5]) should return [1, 2, 3, 4, 5].

make sure your function has return then your answer

function nonMutatingConcat(original, attach){ return original.concat(attach); };

I always forget to do that. the syntax is correct though

Use the arguments in the function and not the arrays as a whole.
Try solving now.

function nonMutatingConcat(original, attach) {
// Add your code below this line
return original.concat(attach);

// Add your code above this line
}
var first = [1, 2, 3];
var second = [4, 5];
nonMutatingConcat(first, second);

This code is my solution.

Thank you very much for helping .

1 Like