I have an array of dates. I have a specific date "Search Date". I want to find the date in the array that is closest to but less than the Search Date and return the index of that date in the array.
Example: Suppose the array of dates is [8/1/21, 8/5/22, 8/5/23], indexed 1,2,3 for sake of example. Suppose my Search date is 9/17/22. The function should find the date 8/5/22 and return the index 2.
In Google Sheets, this is simply the match function:

How do I do this (and most efficiently) in Apps Script? The IndexOf() function seems to return only an exact match, which does not work in this case.
Thank you!
