esnext.math.clamp.js 286 B

123456789101112
  1. var $ = require('../internals/export');
  2. var min = Math.min;
  3. var max = Math.max;
  4. // `Math.clamp` method
  5. // https://rwaldron.github.io/proposal-math-extensions/
  6. $({ target: 'Math', stat: true }, {
  7. clamp: function clamp(x, lower, upper) {
  8. return min(upper, max(lower, x));
  9. }
  10. });