

See carefully what they need in the output result ,they want the result to be like this :įrankenSplice(,, 1) should return, in other words they want from you to use slice and splice, slice for copying arr2 because they want arr2 to be unchanged, and then you can use splice to add elements from copying array that you got from slice method and as it known the splice method has three parameters, array.splice(index, howmany, item1, …, itemX) here index=n and n is from where you can start adding ,howmany should stay 0,and item1=the element you wanna add to the copied array. frankenSplice(\'claw\', \'tentacle\', \'head\', \'shoulders\', \'knees\', \'toes\', 2) \'head\', \'shoulders\', \'claw\', \'tentacle\', \'knees. Copy each element of the first array into the second array, in order. Math.floor () will round down to give the left side one less than the right side for odd lengths.

I see two ways of achieving what you want: Assigning the result of concat to b (it will break the reference to the original array, since it is a fresh new one). It accepts three arguments: The first parameter (start) specifies the index where an element should be inserted or removed. It returns removed elements in a new array. Unlike slice, the method splice mutates the original array. splice () actually removes elements from the source array, the remaining elements in the array will be the elements for the right half. has no side effects, meaning it does not modify the original array (i.e. The method splice() is used to add and remove elements from an array in JavaScript.

In your code( the const end) is just concatenating the two element 5 and 6 from arr2 to arr1 ,and concat method is not suitable here var leftSide arrayName.splice (0, Math.floor (arrayName.length / 2)) Since.
