Basic Algorithm Scripting - Where do I Belong

Tell us what’s happening:
Describe your issue in detail here.
Can you tell me what is wrong with my code? Thank you.

  **Your code so far**
function getIndexToIns(arr, num) {
for(let i = 0; i < arr.length; i++){
  if(arr[i] < num ){
   arr.splice(arr[i] , 0, num)
  }
}
return arr.indexOf(num)
}

console.log(getIndexToIns([40, 60], 50));
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36

Challenge: Basic Algorithm Scripting - Where do I Belong

Link to the challenge:

Can you explain in detail what you think this part of your code is doing?

1 Like

I think the logic in my code is wrong, so I will have to try another way. Thanks for your help.