array-slice-simple.js 584 B

12345678910111213141516
  1. var toAbsoluteIndex = require('../internals/to-absolute-index');
  2. var lengthOfArrayLike = require('../internals/length-of-array-like');
  3. var createProperty = require('../internals/create-property');
  4. var $Array = Array;
  5. var max = Math.max;
  6. module.exports = function (O, start, end) {
  7. var length = lengthOfArrayLike(O);
  8. var k = toAbsoluteIndex(start, length);
  9. var fin = toAbsoluteIndex(end === undefined ? length : end, length);
  10. var result = $Array(max(fin - k, 0));
  11. for (var n = 0; k < fin; k++, n++) createProperty(result, n, O[k]);
  12. result.length = n;
  13. return result;
  14. };