Created
December 16, 2021 07:33
-
-
Save alejandrolechuga/57e28ddc8e1ec195ee514c42e3ae642c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// clamp | |
// 10 al 100 | |
// 9 -> 10 | |
// 199 -> 100 | |
// 50 -> 50 | |
// min 5 | |
// max 100 | |
function limitarCompra(numArticulos) { | |
let min = 5; | |
let max = 100; | |
return clamp(numArticulos, min, max); | |
} | |
function clamp(num, min, max) { | |
return Math.min(Math.max(num, min), max); | |
} | |
console.log(limitarCompra(2)); // 5 | |
console.log(limitarCompra(40)); // 40 | |
console.log(limitarCompra(199)); // 100 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment