Where do I Belong (Different Approach)

Tell us what’s happening:
Well i have cleared this challenge but what if i passed an array with multiple same numbers and I wanted the index of the last of the group of same numbers. For example, array is [1,3,3,5,5,6] and num is 5, the console will return 3 but I want it to be 5. Help appreciated!

Your code so far

function getIndexToIns(arr, num) {
  arr.sort(function(a, b) {
    return a - b;
  for(var i=0; i < arr.length; i++){
             return i;
         return arr.length;

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36.

Link to the challenge:

Well, how would you do it? It’s a great modification to the challenge and you’d definitely learn something by getting it to work.

Hint: return exits the function early

I found two simple solutions, what about you?