Skip to content

Instantly share code, notes, and snippets.

@phpsmarter
Created January 23, 2022 03:29
Show Gist options
  • Save phpsmarter/0ce199fda34777dc510b4e1e8253a956 to your computer and use it in GitHub Desktop.
Save phpsmarter/0ce199fda34777dc510b4e1e8253a956 to your computer and use it in GitHub Desktop.
钳位函数
export const clamp = (x: number, min: number, max: number): number => {
if (x < min)
return min;
if (x > max)
return max;
return x;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment