3.8 KiB
3.8 KiB
id | title | isRequired | isBeta | challengeType | videoUrl | localeTitle |
---|---|---|---|---|---|---|
579e2a2c335b9d72dd32e05c | Slice and Splice | true | true | 5 | Нарезка и сращивание |
Description
slice
и splice
для копирования каждого элемента первого массива во второй массив по порядку. Начните вставлять элементы в индекс n
второго массива. Верните результирующий массив. Входные массивы должны оставаться неизменными после запуска функции. Не забудьте использовать Read-Search-Ask, если вы застряли. Напишите свой собственный код. Instructions
Tests
tests:
- text: '<code>frankenSplice([1, 2, 3], [4, 5], 1)</code> должен вернуться <code>[4, 1, 2, 3, 5]</code> .'
testString: 'assert.deepEqual(frankenSplice([1, 2, 3], [4, 5], 1), [4, 1, 2, 3, 5], "<code>frankenSplice([1, 2, 3], [4, 5], 1)</code> should return <code>[4, 1, 2, 3, 5]</code>.");'
- text: '<code>frankenSplice([1, 2], ["a", "b"], 1)</code> должны возвращать <code>["a", 1, 2, "b"]</code> .'
testString: 'assert.deepEqual(frankenSplice(testArr1, testArr2, 1), ["a", 1, 2, "b"], "<code>frankenSplice([1, 2], ["a", "b"], 1)</code> should return <code>["a", 1, 2, "b"]</code>.");'
- text: '<code>frankenSplice(["claw", "tentacle"], ["head", "shoulders", "knees", "toes"], 2)</code> должны возвращать <code>["head", "shoulders", "claw", "tentacle", "knees", "toes"]</code> .'
testString: 'assert.deepEqual(frankenSplice(["claw", "tentacle"], ["head", "shoulders", "knees", "toes"], 2), ["head", "shoulders", "claw", "tentacle", "knees", "toes"], "<code>frankenSplice(["claw", "tentacle"], ["head", "shoulders", "knees", "toes"], 2)</code> should return <code>["head", "shoulders", "claw", "tentacle", "knees", "toes"]</code>.");'
- 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
function frankenSplice(arr1, arr2, n) {
// It's alive. It's alive!
return arr2;
}
frankenSplice([1, 2, 3], [4, 5, 6], 1);
After Test
console.info('after the test');
Solution
// solution required