I need a simple solution for the following scenario:
let rangeOfInterest = [25 , 44];
let input = [10, 20, 30, 40, 50, 60];
I want to extract values that fall between 25 and 44 (inclusive) from the given input. The range may be within or outside the input values completely, for example [85, 95] or [0, 100].
output1 = [30, 40];
If there are values adjacent to this output, I also want to include them;
finalOutput = [20, 30, 40, 50];
Currently, I achieve this by filtering the array and identifying the indexes of the first and last elements in the result to extract additional samples if needed. Is there a more concise approach without using approximately 20 lines of code?
Note: The sample values will be floating-point numbers, but integers are used in this simplified example.