Tell us what’s happening:
I have checked some of the tests in my challenge using console.log() and they are returning the correct value, but none of the tests pass.
Describe your issue in detail here:
If I include a console.log(); function in my script, outside of the getIndexToIns() function, and input
getIndexToIns([10, 20, 30, 40, 50], 35)
in the log like in the code below, it returns the number 3. However the test for this scenario does not pass, as shown in the image below.
I have tried a few more of the tests, as well as not logging any result with console.log(), and all of the tests fail no matter what.
It definitely seems to be a technical problem rather than a bug in the code. Let me know if you know what’s happening or need more information. Thanks.
Your code so far
function getIndexToIns(arr, num) {
arr.sort((a, b) => a - b);
for (let index in arr)
if (num <= arr[index])
return index;
}
console.log(getIndexToIns([10, 20, 30, 40, 50], 35));
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/108.0.0.0 Safari/537.36
Challenge: Basic Algorithm Scripting - Where do I Belong
Link to the challenge: