Though I know how to solve this with the for loop I avoided it and wanted to know what’s wrong with the solution I coded.
Appreciate any feedback.
function frankenSplice(arr1, arr2, n) {
let i;
Number.isInteger(n) ? i = n : i = arr2.indexOf(n);
let arr3 = arr2.slice();
arr3.splice(i,0,arr1);
return arr3;
}
console.log(frankenSplice(["claw", "tentacle"], ["head", "shoulders", "knees", "toes"], 2));
console.log(arr3);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:64.0) Gecko/20100101 Firefox/64.0
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/slice-and-splice