I need to find the closest number in an array that is not higher than a specified number. Here's an example scenario:
Let's say we have an array:
[1, 3, 7, 15, 40, 55, 70, 80, 95]
The variable for the number is: numberD1
;
If numberD1 is 8 - The closest number should be 7, not 15.
If numberD1 is 54 - The closest number should be 40, not 55.
In other words, I want to find the closest number in the array that is not greater than the selected number (similar to the Math.floor()
function).
I apologize for any grammar errors in my English. I hope I have explained my issue clearly.