Tell us what’s happening:
Your code so far
Hi. I have tested this code on my browser, on https://ronakshah.net/console/ and result is Ok, but on freeCodeCamp I get “TypeError: unknown: Cannot read property ‘0’ of undefined”.
What is the matter?
Please, who can explain me.
function getIndexToIns(arr, num) {
// Find my place in this sorted array.
arr1 = arr.concat(num);
arr2 = arr1.sort((x,y)=>x-y);
for(var i = 0; i<arr2.length; i++)
if(arr2[i]===num)
return i;
}
getIndexToIns([40, 60], 50);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36 OPR/63.0.3368.71
.
Link to the challenge: