to-absolute-index.js 439 B

123456789101112
  1. var toInteger = require('../internals/to-integer');
  2. var max = Math.max;
  3. var min = Math.min;
  4. // Helper for a popular repeating case of the spec:
  5. // Let integer be ? ToInteger(index).
  6. // If integer < 0, let result be max((length + integer), 0); else let result be min(integer, length).
  7. module.exports = function (index, length) {
  8. var integer = toInteger(index);
  9. return integer < 0 ? max(integer + length, 0) : min(integer, length);
  10. };