FunkPanion/scripts/ArrayUtils.gd

19 lines
382 B
GDScript3
Raw Normal View History

2024-11-23 20:36:52 +00:00
class_name ArrayUtils
static func get_sclosest(array:Array, target:Variant, error = 0):
var floor = 0
var ceil = array.size() - 1
var closest = error
while floor <= ceil:
var searchPoint = floor((floor + ceil) / 2)
var num = array[searchPoint]
if num <= target:
closest = searchPoint
floor = searchPoint + 1
else:
ceil = searchPoint - 1
return closest