Hi guys, I’m baffled as to why my code wont pass even though it is logging out the right answer.
I’m using a for in loop which wont pass. But when I use a normal for loop, to achieve the same exact answer, it passes. Any idea why?
Your code so far
function getIndexToIns(arr, num) {
const target = num;
arr.push(num);
arr.sort(sortNumber);
for (var i in arr) {
if (arr[i] === target) {
return i;
}
}
}
function sortNumber(a,b) {
return a - b;
}
getIndexToIns([2, 20, 10], 19);
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36
.
Link to the challenge:
https://www.freecodecamp.org/challenges/where-do-i-belong