This may make it more obvious
If val is 380, what will that function return? According to my fat-fingered calculations, 380 is less than minButtonVal[0], so the function should return 0, indicating that the 0th switch was pressed. But, 0 means no switch was pressed.
Why doesn't -1 mean that no switch was pressed?