Skip to content

Latest commit

 

History

History
13 lines (9 loc) · 1.61 KB

File metadata and controls

13 lines (9 loc) · 1.61 KB

clamp easy #javascript

by Pawan Kumar @jsartisan

Take the Challenge

Implement a function similar to _.clamp from the Lodash library. The function clamp takes three arguments: a number, a lower bound, and an upper bound. The function returns the number clamped within the inclusive lower and upper bounds.

Example usage

console.log(clamp(10, 5, 15)); // 10
console.log(clamp(4, 5, 15)); // 5
console.log(clamp(20, 5, 15)); // 15

Back Share your Solutions Check out Solutions