source: trip-planner-front/node_modules/core-js/modules/es.array.splice.js@ b738035

Last change on this file since b738035 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.6 KB
Line 
1'use strict';
2var $ = require('../internals/export');
3var toAbsoluteIndex = require('../internals/to-absolute-index');
4var toInteger = require('../internals/to-integer');
5var toLength = require('../internals/to-length');
6var toObject = require('../internals/to-object');
7var arraySpeciesCreate = require('../internals/array-species-create');
8var createProperty = require('../internals/create-property');
9var arrayMethodHasSpeciesSupport = require('../internals/array-method-has-species-support');
10
11var HAS_SPECIES_SUPPORT = arrayMethodHasSpeciesSupport('splice');
12
13var max = Math.max;
14var min = Math.min;
15var MAX_SAFE_INTEGER = 0x1FFFFFFFFFFFFF;
16var MAXIMUM_ALLOWED_LENGTH_EXCEEDED = 'Maximum allowed length exceeded';
17
18// `Array.prototype.splice` method
19// https://tc39.es/ecma262/#sec-array.prototype.splice
20// with adding support of @@species
21$({ target: 'Array', proto: true, forced: !HAS_SPECIES_SUPPORT }, {
22 splice: function splice(start, deleteCount /* , ...items */) {
23 var O = toObject(this);
24 var len = toLength(O.length);
25 var actualStart = toAbsoluteIndex(start, len);
26 var argumentsLength = arguments.length;
27 var insertCount, actualDeleteCount, A, k, from, to;
28 if (argumentsLength === 0) {
29 insertCount = actualDeleteCount = 0;
30 } else if (argumentsLength === 1) {
31 insertCount = 0;
32 actualDeleteCount = len - actualStart;
33 } else {
34 insertCount = argumentsLength - 2;
35 actualDeleteCount = min(max(toInteger(deleteCount), 0), len - actualStart);
36 }
37 if (len + insertCount - actualDeleteCount > MAX_SAFE_INTEGER) {
38 throw TypeError(MAXIMUM_ALLOWED_LENGTH_EXCEEDED);
39 }
40 A = arraySpeciesCreate(O, actualDeleteCount);
41 for (k = 0; k < actualDeleteCount; k++) {
42 from = actualStart + k;
43 if (from in O) createProperty(A, k, O[from]);
44 }
45 A.length = actualDeleteCount;
46 if (insertCount < actualDeleteCount) {
47 for (k = actualStart; k < len - actualDeleteCount; k++) {
48 from = k + actualDeleteCount;
49 to = k + insertCount;
50 if (from in O) O[to] = O[from];
51 else delete O[to];
52 }
53 for (k = len; k > len - actualDeleteCount + insertCount; k--) delete O[k - 1];
54 } else if (insertCount > actualDeleteCount) {
55 for (k = len - actualDeleteCount; k > actualStart; k--) {
56 from = k + actualDeleteCount - 1;
57 to = k + insertCount - 1;
58 if (from in O) O[to] = O[from];
59 else delete O[to];
60 }
61 }
62 for (k = 0; k < insertCount; k++) {
63 O[k + actualStart] = arguments[k + 2];
64 }
65 O.length = len - actualDeleteCount + insertCount;
66 return A;
67 }
68});
Note: See TracBrowser for help on using the repository browser.