I updated clamp and bounds.

This commit is contained in:
root 2024-10-09 14:59:42 -04:00
parent b3603aeeb6
commit 9271a15c2c
1 changed files with 4 additions and 20 deletions

View File

@ -26,34 +26,18 @@ def minimum(data):
def bounds(data):
"Returns a list of the smallest and largest numbers in data"
lowest = None
for number in data:
if lowest is None:
lowest = number
if number < lowest:
lowest = number
highest = None
for number in data:
if highest is None:
highest = number
if number > highest:
highest = number
return [lowest, highest]
return [minimum(data), maximum(data)]
def clamp(value, low, high):
"""Clamps a value to a range from low to high.
Returns value if it is between low and high.
If value is lower than low, returns low. If value is higher than high, returns high.
"""
if low < value < high:
if low < value and value < high:
return value
if value < low:
if value <= low:
return low
if value == low:
return low
if value > high:
return high
if value == high:
if value >= high:
return high