Why does this solution work for all but these cases;
getIndexToIns([10, 20, 30, 40, 50], 35) should return 3 .
getIndexToIns([40, 60], 50) should return 1 .
getIndexToIns([2, 20, 10], 19) should return 2 .
getIndexToIns([2, 5, 10], 15) should return 3 .
function getIndexToIns(arr, num) {
let x = arr.sort(function(a,b){return a-b});
console.log(x);
let v,k;
if(x.length >0){
x.forEach( (e) => {
if (e<=num){
k = x.indexOf(e);
}
})
}
else {
k = 0;
}
return k;
}
getIndexToIns([40, 60], 50);
