FunkPanion/scripts/ArrayUtils.gd
2024-11-23 14:36:52 -06:00

18 lines
382 B
GDScript

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