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