Hello,
I’ve try to solve this challenge like this
function getIndexToIns(arr, num) {
// Find my place in this sorted array.
arr.sort();
for (i = 0; i < arr.length; i++) {
if (arr[i] <= num <= arr[i + 1]) {
return(arr.indexOf(arr[i]));
}
}
}
For an unknow reason to me it didn’t work but I think the logic should work right ?
I’ve check the hint and found that logic even more clear, I managed to redo it by myself but I would still like to understand why the first code didn’t work
arr.sort();
var final = 0;
for (i = 0; i < arr.length; i++) {
if (num > arr[i]) {
final += 1;
}
}
return final;
}