Implement a Sorted Index Finder | javascript filter method use

function getIndexToIns(array, target){
if(array.length == 0){
   return 0;
}
array.sort((a,b)=> a-b)
const index = array.findIndex((val) =>
val > target | val == target
);

return index;
}

I passed all the test except this one.

11. getIndexToIns([3, 10, 5], 11) should return 3

I can’t figure out how to return an index out of length in this case. my filter method is not going upto that position. what would fix this code.

what value is your function returning instead? you could use that as a starting point

Ohhh I got it. It returns -1 if no match found. I can check that and return one index up of the last element which is array length.

Here is the final code that passed all test successfully.

removed

Arigato Guzaimas

Please do not share solution code on the form, thanks.

It is great that you solved the challenge, but we are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

Arigatou gozaimasu :+1: