Https://www.freecodecamp.com/challenges/where-do-i-belong

function getIndexToIns(arr, num) {
// Find my place in this sorted array.

for(var i = 0; i < arr.length ; i++){
arr.sort();
if(num <= arr[i]){
return arr.indexOf(arr[i]);

}
}
return arr.length;
}

getIndexToIns([3,5,20], 3);

can you please tell me whats wrong with my code? i cant get the output for this one.

try this:
function getIndexToIns(arr, num) {
// Find my place in this sorted array.

for(var i = 0; i < arr.length ; i++){
arr.sort(function(a,b){return a-b;})
if(num <= arr[i]){
return arr.indexOf(arr[i]);

}
}
return arr.length;

thank you so much!!! i finally got it :smiley:

thanks a lot :slight_smile: i got it now