Lodash clamp method
语法
_.clamp(number, [lower], upper)
Clamps number within the inclusive lower and upper bounds.
参数
number (number) − The number to clamp.
[lower] (number) − The lower bound.
upper (number) − The upper bound.
输出
(number) − Returns the clamped number.
实例
var _ = require('lodash');
var result = _.clamp(-12,-2, 2);
console.log(result);
result = _.clamp(12,-2, 2);
console.log(result);
Save the above program in
tester.js. Run the following command to execute this program.
Command
输出