to-absolute-index.js 471 B

123456789101112
  1. var toIntegerOrInfinity = require('../internals/to-integer-or-infinity');
  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 = toIntegerOrInfinity(index);
  9. return integer < 0 ? max(integer + length, 0) : min(integer, length);
  10. };