I was trying to solve the problem of the slice, splice algorithm.I was solved with my way and my solution is working for all steps but I don’t know why my solution doesn’t accept by system.
The task is: You are given two arrays and an index.
Copy each element of the first array into the second array, in order.
Begin inserting elements at index n
of the second array.
Return the resulting array. The input arrays should remain the same after the function runs.
The first and second arrays should remain the same after the function runs.
My Solutions is :
function frankenSplice(arr1, arr2, n) {
let z = arr2.slice(0, arr2.length);let x = arr2.splice(n, arr2.length, …arr1);
arr2.splice(arr2.length, arr2.length, …x);
let result = arr2.slice(0, arr2.length);
arr2 = z;
console.log(arr2);
console.log(arr1);return result;
}console.log(
frankenSplice([“claw”, “tentacle”], [“head”, “shoulders”, “knees”, “toes”], 2)
);