Clamp a number between a minimum number and a maximum number

The advantage of a function, is that it does not cause confusion between the min function, and the cocept of minumum.

function clamp(targetNum, min, max) {
	if(max < min) {
		const temp = max
		max = min
		min = temp
	if(targetNum < min) {
		return min
	if(targetNum > max) {
		return max
	return targetNum