Created
April 29, 2020 13:27
-
-
Save dainiuxt/dc5aed83fb8df0f732395f6ddbfaa89e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Free c code camp task | |
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-algorithm-scripting/slice-and-splice | |
Are there any flaws in my solution (code passes test as OK)? | |
You are given two arrays and an index. | |
Use the array methods slice and splice to 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. | |
*/ | |
function frankenSplice(arr1, arr2, n) { | |
var firstArr = arr2.slice(0, n); | |
var thirdArr = arr2.slice(n); | |
var inter = firstArr.concat(arr1); | |
var result = inter.concat(thirdArr); | |
return result; | |
} | |
frankenSplice([1, 2, 3], [4, 5], 1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment