- If num falls within the range, return num.
- Otherwise, return the nearest number in the range.
//#Source https://bit.ly/2neWfJ2 const clampNumber = (num, a, b) => Math.max(Math.min(num, Math.max(a, b)), Math.min(a, b)); console.log(clampNumber(2, 3, 5)); console.log(clampNumber(1, -1, -5));
Improve this sample solution and post your code through Disqus
What is the difficulty level of this exercise?
const name = 'Owen'; console.log(name());
The variable name holds the value of a string, which is not a function, thus cannot invoke.
- New Content published on w3resource:
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework