Tell us what’s happening:
My loop running a condition to check each array item that is typeof = “string” checking if it isNaN to return it as-is, as a string, else converts the number into a number results in an array that replaces all strings to NaN.
Your code so far
function frankenSplice(arr1,arr2,index) {
let newArr = arr2.slice(0);
let tempArr = arr1.slice(0);
newArr.splice(index, 0, tempArr);
const arrayFromString = String(newArr).split(',');
let resultArr =[];
for (let i =0; i < arrayFromString.length; i++) {
if (isNaN(Number(arrayFromString[i])) === "true") {resultArr[i] = arrayFromString[i];
}
else {resultArr[i] = Number(arrayFromString[i]);}
}
return resultArr;
}
console.log(frankenSplice([1, 2], ["a", "b"], 1))
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:144.0) Gecko/20100101 Firefox/144.0
Challenge Information:
Implement the Slice and Splice Algorithm - Implement the Slice and Splice Algorithm