The findIndex looks for the first element that meets your criteria (the callback returns true). If it never sees a match, it returns -1. This is the case you are failing, when num is larger than anything in the array.
So, if the num is larger than anything in arr, it will never match so it will return -1. Armed with that knowledge, what should the index be?
One solution would be to put in some logic return the correct index if -1 is returned.
There is another way to solve it, but it would involve changing how you find the index. Either solution is fine.
Also, fyi, if you use the “Ask for help” button, on the challenge, it will post to the forum with links to the forum with links to the challenge so we don’t have to go looking for it.
Stylistically, remember to indent properly - it saves headaches in the long run.
I would also say, that after:
if (arr.length == 0) {
return 0;
}
you don;t need the else clause, because you are returning out of the function. Nothing after the return will get run anyway. It is very common to do something like:
if (arr.length == 0) {
return 0;
}
let myArray = arr.sort(function compare(a,b) {
//...
It saves you a level of indent which improves readability.
Let us know if this hint is insufficient.