Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

clamp function js

// Javascript
const clamp = (number, min, max) =>
   Math.max(min, Math.min(number, max));

// Typescript
const clamp = (number: number, min: number, max: number) =>
   Math.max(min, Math.min(number, max));
Comment

js clamp

function clamp(n, min, max) {
  if(n > max){
  	return max;
  } else if(n < min){
    return min
  } else{
  	return n;
  }
}
//clamp(202, 1,100); //returns 100
//clamp(50,1,100); //returns 50
//clamp(-3,1,100); //returns 1
Comment

PREVIOUS NEXT
Code Example
Javascript :: js check if number has decimals 
Javascript :: Check if local storage is used or empty 
Javascript :: sort array of objects javascript by value 
Javascript :: option selected jquery 
Javascript :: redirect using javascript 
Javascript :: javascript redirect to 
Javascript :: location javascript redirect 
Javascript :: redirect to html page in javascript 
Javascript :: vehicle number formik validation 
Javascript :: while loop countdown javascript 
Javascript :: ng build prod 
Javascript :: regex for entire word 
Javascript :: sort multidimensional array javascript 
Javascript :: if statement es6 
Javascript :: Error: [ProtectedRoute] is not a <Route component 
Javascript :: get file name nodejs 
Javascript :: pick random from array 
Javascript :: add color to console 
Javascript :: check if not checked vanila js 
Javascript :: image not showing js 
Javascript :: javascript add element next to another 
Javascript :: how to change active tab jquery 
Javascript :: import resolver path react 
Javascript :: jquery change picture onclick 
Javascript :: javascript get unique values from key 
Javascript :: check if over 18 javascript 
Javascript :: javascript un hiden element 
Javascript :: selecionar valselect2 js 
Javascript :: array from comma separated string javascript 
Javascript :: vuejs string contains 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =