Just completed this challenge completely on my own without looking for clues online so I’m pretty stoked. Would love to get some feedback on my code as to how I can write it better or more efficiently.
function getIndexToIns(arr, num) {
var sorted = arr.sort(function(a, b){
return a - b;
});
for (var i = 0;i<sorted.length;i++) {
if (num > sorted[i] && num < sorted[i+1])
sorted.splice(i+1, 0, num);
else if (num > sorted[i]) {
sorted.push(num);
} else {
return sorted.indexOf(num);
}
}
}
thanks