main
Last change
on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Line | |
---|
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 | // `Array.prototype.copyWithin` method implementation
|
---|
10 | // https://tc39.es/ecma262/#sec-array.prototype.copywithin
|
---|
11 | // eslint-disable-next-line es/no-array-prototype-copywithin -- safe
|
---|
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 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.