source: trip-planner-front/node_modules/core-js/internals/flatten-into-array.js@ 6a80231

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

initial commit

  • Property mode set to 100644
File size: 1.1 KB
Line 
1'use strict';
2var isArray = require('../internals/is-array');
3var toLength = require('../internals/to-length');
4var bind = require('../internals/function-bind-context');
5
6// `FlattenIntoArray` abstract operation
7// https://tc39.github.io/proposal-flatMap/#sec-FlattenIntoArray
8var flattenIntoArray = function (target, original, source, sourceLen, start, depth, mapper, thisArg) {
9 var targetIndex = start;
10 var sourceIndex = 0;
11 var mapFn = mapper ? bind(mapper, thisArg, 3) : false;
12 var element;
13
14 while (sourceIndex < sourceLen) {
15 if (sourceIndex in source) {
16 element = mapFn ? mapFn(source[sourceIndex], sourceIndex, original) : source[sourceIndex];
17
18 if (depth > 0 && isArray(element)) {
19 targetIndex = flattenIntoArray(target, original, element, toLength(element.length), targetIndex, depth - 1) - 1;
20 } else {
21 if (targetIndex >= 0x1FFFFFFFFFFFFF) throw TypeError('Exceed the acceptable array length');
22 target[targetIndex] = element;
23 }
24
25 targetIndex++;
26 }
27 sourceIndex++;
28 }
29 return targetIndex;
30};
31
32module.exports = flattenIntoArray;
Note: See TracBrowser for help on using the repository browser.