Where do I belong- need help

the last couple algorithms have been challenging to say the least and I had to look at the solution. I don’t want to do that with this one, so can someone please point me in the right direction without actually telling me the solution?
The problem is that indexOf() is not returning what I want.
Here’s my code:

function getIndexToIns(arr, num) {
  function compareNumbers(a, b){
    return a - b;
 for (var n = 0; n < arr.length; n++) {
     if(arr[n] > num && num < arr[n]+1){ 
       return arr.indexOf(arr[n])-1;
       else if (num === arr[n] || num < arr[n]){
       return 0;
getIndexToIns([40, 60], 50);

Thanks in advance!

  • if(arr[n] > num && num < arr[n]+1) What are you trying to do with this conditional? Right now it’s “if num is less than the nth item of arr and also less than the nth item of arr plus one”

  • arr.indexOf(arr[n]) should just return n. It’s basically saying “what is the index of the item at this index?”

I see. I was trying to find the next bigger number after num and return its index.