Basic Algorithm Scripting - Slice and Splice

Tell us what’s happening:
The description of this challenge is not fully clear.
Because as I see that the output in one case is taking the first element only and then adding the rest oft the array at the end of arr2 (see example one)

while in example 2 it takes the entire array and addes it to the arr2 in the specified index(this is what we understand while the 1st example seems to be falsy test)

Am I missing something here ?

  **Your code so far**
function frankenSplice(arr1, arr2, n) {
let arr1S=arr1.slice();
let arr2S=arr2.slice();
return arr2S.splice(n,0,...arr1S);
}

frankenSplice([1, 2, 3], [4, 5, 6], 1);
  **Your browser information:**

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

Challenge: Basic Algorithm Scripting - Slice and Splice

Link to the challenge:

Could you clarify, what is example1 and example2? I am not sure if I understood that.

I meant the tests that where provided … Here it is

first frankenSplice([1, 2, 3], [4, 5], 1)should return[4, 1, 2, 3, 5]`.
as you see in this the no 5 is in the the end of the array !

second frankenSplice([1, 2], [“a”, “b”], 1)should return[“a”, 1, 2, “b”]`.

Yeah, I see 5 in the end, but it’s ok I guess.

Lets look at it:

you should insert in this array
the array below:

starting from index 1.
So we have this as expected result:

[4, 1, 2, 3, 5]

1, 2, 3 - elements of the first array we placed them into second one, starting from index 1.

[
4, //index 0
1, //index 1
2, //index 2
3, //index 3
5 //index 4
]

Why do you think 5 is a problem here?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.