Yeah I'd just use a loop. I'm not sure why find is not doing what's expected though... Also you don't need to set the second parameter as myArray because that's already there in the third parameter of the test function.
This is what I would do
local myArray = [0, 5, 10, 15, 20]; local element; for (x in myArray) { if (sample <= x) { element = x; break; } }