So I thought I had solved this. I’ve searched, I’ve used console.log() but I can’t understand why I’m not passing this assignment. I pass most of the tests, but there a few select parameters that when passed into my function do not return the correct index. I’m including one of those sets below. What am I doing wrong?
Thanks,
Your code so far
function getIndexToIns(arr, num) {
let value = "";
arr.sort((a, b) => a - b);
for (let i = 0; i < arr.length; i++) {
if (num >= arr[i]) {
value = arr.indexOf(arr[i]);
}
}
return value;
}
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/84.0.4147.135 Safari/537.36.
@miles Glad to see you were able to solve the problem you were facing. Just as an extra bit of information to anyone interested, JavaScript allows for this challenge to be passed without explicitly writing a for loop. As an extra challenge, see if you can get it to pass with only 3 lines of code inside the function (including the return statement) and only using the JavaScript methods push, sort, and indexOf.