debian-mirror-gitlab/core-js/internals/to-absolute-index.js

13 lines
439 B
JavaScript
Raw Normal View History

2019-09-25 13:30:05 +05:30
var toInteger = require('../internals/to-integer');
var max = Math.max;
var min = Math.min;
// Helper for a popular repeating case of the spec:
// Let integer be ? ToInteger(index).
2019-12-04 20:38:33 +05:30
// If integer < 0, let result be max((length + integer), 0); else let result be min(integer, length).
2019-09-25 13:30:05 +05:30
module.exports = function (index, length) {
var integer = toInteger(index);
return integer < 0 ? max(integer + length, 0) : min(integer, length);
};