I'm attempting to refactor my code. I'm pretty sure there is a more efficient way to do this, but I don't really have much of an idea for approaching it.
I have functions to check for a variable amount of values in an array in sequence, and would like to combine them into one function.
Currently my conditions look as follows if I want to check 3 cells:
array value at (startposition+1) < 0
array value at (startposition+2) < 0
array value at (startposition+3) < 0
array set value at startposition+1 to 1
array set value at startposition+2 to 1
array set value at startposition+3 to 1
If I wanted to check and modify 10 cells, I would need to set up 10 conditions and 10 actions.
I thought briefly of using loops, but the problem with that is I want all conditions met (check every cell) before modifying anything. When I tried a loop, the function modified each cell as it went, and just skipped over the cells that didn't meet the condition. If there are any cells in the range that don't meet the condition, I don't want any action to be made.
Basically I wonder if there is a way to have a condition check each contiguous cell in an array from x to x+y for a value, and if true, set values for each cell from x to x+y, where x (starting point) and y (number of cells to check) are function parameters. Currently it looks like I have to check each array cell with a separate condition first.
Any help would be appreciated.