Hi everyone, hope you’re all having fun. I hit the “Where Do I Belong” challenge last night and though my first solution was very simple, I kept wondering what would happen if the list were 1000 elements long and the actual place for insertion happened to be at the end of the list. I tried something else instead, which involved pruning away half the list and then iterating through the remainder. From my (dated) knowledge I recall that as being a binary tree search, but I’m not clear on the implementation in Javascript.

Can anyone review my code below and provide some guidance on how I could implement same towards solving this problem? Would greatly appreciate it!

```
function getIndexToIns(arr, num) {
// Find my place in this sorted array.
arr.sort(function(a,b){
return a-b;
});
var i;
//Partition the array into items greater than/equal to or less than than num and iterate through the remainder...
var searchIdx = Math.ceil(arr.length/2) - 1;
if(arr[searchIdx] == num){
return searchIdx;
} else if(arr[searchIdx] > num){
for(i = searchIdx; i >=0; i--){
if(arr[i] <= num){
return i;
}
}
} else if(arr[searchIdx] < num){
for(i = searchIdx; i < arr.length; i++){
if(arr[i] >= num){
return i;
}
}
}
return i;
}
```