1 | 'use strict';
|
2 | var toObject = require('../internals/to-object');
|
3 | var toAbsoluteIndex = require('../internals/to-absolute-index');
|
4 | var lengthOfArrayLike = require('../internals/length-of-array-like');
|
5 | var deletePropertyOrThrow = require('../internals/delete-property-or-throw');
|
6 |
|
7 | var min = Math.min;
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | module.exports = [].copyWithin || function copyWithin(target /* = 0 */, start /* = 0, end = @length */) {
|
13 | var O = toObject(this);
|
14 | var len = lengthOfArrayLike(O);
|
15 | var to = toAbsoluteIndex(target, len);
|
16 | var from = toAbsoluteIndex(start, len);
|
17 | var end = arguments.length > 2 ? arguments[2] : undefined;
|
18 | var count = min((end === undefined ? len : toAbsoluteIndex(end, len)) - from, len - to);
|
19 | var inc = 1;
|
20 | if (from < to && to < from + count) {
|
21 | inc = -1;
|
22 | from += count - 1;
|
23 | to += count - 1;
|
24 | }
|
25 | while (count-- > 0) {
|
26 | if (from in O) O[to] = O[from];
|
27 | else deletePropertyOrThrow(O, to);
|
28 | to += inc;
|
29 | from += inc;
|
30 | } return O;
|
31 | };
|