Slice and Splice Results are as expected, however it is not accepted as a solution, when using the requested methods

Tell us what’s happening:
I do not understand why this is not accepted, the results are as expected and is of type object.

Your code so far


function frankenSplice(arr1, arr2, n) {
  // It's alive. It's alive!
  let arr3 = arr2.slice(0);
  arr3.splice(n, 0, arr1);
  console.log(arr3);
  console.log(typeof arr3);
  return arr3;
}

frankenSplice([1, 2], ["a", "b"], 1);

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.102 Safari/537.36 Vivaldi/2.6.1566.44.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/slice-and-splice

frankenSplice([1, 2], [“a”, “b”], 1) should return ** ["a", 1, 2, "b"]*, but your function is returning:

[ "a", [ 1, 2 ], "b" ]

You are splicing in the entire arr1 into arr2. Instead, you are supposed to be splicing in the elements of arr1 into arr2.

1 Like

I am guessing I could have used JSON to display this object to know that?

You can use your browser’s console to see that with a console.log statement before the return statement.

Thank you very much Randell… Check it. I don’t really care for iterating with the way they do through a for loop, this is what I came up with… http://imgs.fyi/img/8hiv.png

Not sure who “they” are. I strongly recommend not creating these global window variables.

window.n = n;

window.arr3 = arr3;

Your solution is not very efficient (using two splices). You don’t even need to iterate through any arrays to solve this challenge. Think about a special operator you learned about in the ES6 section you could use here you could use with a single splice to solve this challenge.

By “they” I just meant the camp… Just seemed like more code. I reviewed the ES6 section and think I have the solution you were talking about. image