I have a problem on a JS freeCodeCamp exercise-test under Basic Algorithm Scripting / exercise No. 14 - “Where do I Belong?”:
In my IDE and browser console I am getting the correct results with my code, but it seems I messed something (despite correct results) as I can not pass through to the next exercise, and I do not understand what is the problem either, so please help, anyone?
My code - solution:
function getIndexToIns(arr, num) {
arr.push(num);
arr.sort(function(a, b){return a-b});
for(let tempVal in arr){
if(arr[tempVal]===num) {
num = tempVal;
};
};
return num;
};
getIndexToIns([2, 5, 10], 15);
Thank you very much in advance!
Kind regards, SexFalse