1 | 'use strict';
|
---|
2 | var $ = require('../internals/export');
|
---|
3 | var addToUnscopables = require('../internals/add-to-unscopables');
|
---|
4 | var doesNotExceedSafeInteger = require('../internals/does-not-exceed-safe-integer');
|
---|
5 | var lengthOfArrayLike = require('../internals/length-of-array-like');
|
---|
6 | var toAbsoluteIndex = require('../internals/to-absolute-index');
|
---|
7 | var toIndexedObject = require('../internals/to-indexed-object');
|
---|
8 | var toIntegerOrInfinity = require('../internals/to-integer-or-infinity');
|
---|
9 |
|
---|
10 | var $Array = Array;
|
---|
11 | var max = Math.max;
|
---|
12 | var min = Math.min;
|
---|
13 |
|
---|
14 | // `Array.prototype.toSpliced` method
|
---|
15 | // https://tc39.es/ecma262/#sec-array.prototype.tospliced
|
---|
16 | $({ target: 'Array', proto: true }, {
|
---|
17 | toSpliced: function toSpliced(start, deleteCount /* , ...items */) {
|
---|
18 | var O = toIndexedObject(this);
|
---|
19 | var len = lengthOfArrayLike(O);
|
---|
20 | var actualStart = toAbsoluteIndex(start, len);
|
---|
21 | var argumentsLength = arguments.length;
|
---|
22 | var k = 0;
|
---|
23 | var insertCount, actualDeleteCount, newLen, A;
|
---|
24 | if (argumentsLength === 0) {
|
---|
25 | insertCount = actualDeleteCount = 0;
|
---|
26 | } else if (argumentsLength === 1) {
|
---|
27 | insertCount = 0;
|
---|
28 | actualDeleteCount = len - actualStart;
|
---|
29 | } else {
|
---|
30 | insertCount = argumentsLength - 2;
|
---|
31 | actualDeleteCount = min(max(toIntegerOrInfinity(deleteCount), 0), len - actualStart);
|
---|
32 | }
|
---|
33 | newLen = doesNotExceedSafeInteger(len + insertCount - actualDeleteCount);
|
---|
34 | A = $Array(newLen);
|
---|
35 |
|
---|
36 | for (; k < actualStart; k++) A[k] = O[k];
|
---|
37 | for (; k < actualStart + insertCount; k++) A[k] = arguments[k - actualStart + 2];
|
---|
38 | for (; k < newLen; k++) A[k] = O[k + actualDeleteCount - insertCount];
|
---|
39 |
|
---|
40 | return A;
|
---|
41 | }
|
---|
42 | });
|
---|
43 |
|
---|
44 | addToUnscopables('toSpliced');
|
---|