Tests not passing despite returning correct values (Where do I Belong - Basic Algorithm Scripting - JavaScript Algorithms and Data Structures)

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:

Double check the type of your output. You are returning a string.

1 Like

Tysm :smile: I feel kinda stupid since I was convinced it’s a technical issue, but I come from C# where types are very explicit, so I’m not that used to type cheking. I’ll have to keep that in mind when working with JavaScript.

Welcome to the joy of JavaScript types! This one took me a bit to figure out for sure

2 Likes

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.