array-slice-simple.js 634 B

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