--- id: 579e2a2c335b9d72dd32e05c title: Slice and Splice isRequired: true isBeta: true challengeType: 5 videoUrl: '' localeTitle: 切片和拼接 --- ## Description
您将获得两个数组和一个索引。使用数组方法slicesplice按顺序将第一个数组的每个元素复制到第二个数组中。开始在第二个数组的索引n处插入元素。返回结果数组。函数运行后,输入数组应保持不变。如果卡住,请记得使用Read-Search-Ask 。编写自己的代码。
## Instructions
## Tests
```yml tests: - text: 'frankenSplice([1, 2, 3], [4, 5], 1)应该返回[4, 1, 2, 3, 5] frankenSplice([1, 2, 3], [4, 5], 1) [4, 1, 2, 3, 5] 。' testString: 'assert.deepEqual(frankenSplice([1, 2, 3], [4, 5], 1), [4, 1, 2, 3, 5], "frankenSplice([1, 2, 3], [4, 5], 1) should return [4, 1, 2, 3, 5].");' - text: 'frankenSplice([1, 2], ["a", "b"], 1)应返回["a", 1, 2, "b"] 。' testString: 'assert.deepEqual(frankenSplice(testArr1, testArr2, 1), ["a", 1, 2, "b"], "frankenSplice([1, 2], ["a", "b"], 1) should return ["a", 1, 2, "b"].");' - text: 'frankenSplice(["claw", "tentacle"], ["head", "shoulders", "knees", "toes"], 2)应该返回["head", "shoulders", "claw", "tentacle", "knees", "toes"] 。' testString: 'assert.deepEqual(frankenSplice(["claw", "tentacle"], ["head", "shoulders", "knees", "toes"], 2), ["head", "shoulders", "claw", "tentacle", "knees", "toes"], "frankenSplice(["claw", "tentacle"], ["head", "shoulders", "knees", "toes"], 2) should return ["head", "shoulders", "claw", "tentacle", "knees", "toes"].");' - text: 第一个数组中的所有元素都应按原始顺序添加到第二个数组中。 testString: 'assert.deepEqual(frankenSplice([1, 2, 3, 4], [], 0), [1, 2, 3, 4], "All elements from the first array should be added to the second array in their original order.");' - text: 函数运行后,第一个数组应保持不变。 testString: 'assert(testArr1[0] === 1 && testArr1[1] === 2, "The first array should remain the same after the function runs.");' - text: 函数运行后,第二个数组应保持不变。 testString: 'assert(testArr2[0] === "a" && testArr2[1] === "b", "The second array should remain the same after the function runs.");' ```
## Challenge Seed
```js function frankenSplice(arr1, arr2, n) { // It's alive. It's alive! return arr2; } frankenSplice([1, 2, 3], [4, 5, 6], 1); ```
### After Test
```js console.info('after the test'); ```
## Solution
```js // solution required ```