es7.array.flatten.js 745 B

123456789101112131415161718192021
  1. 'use strict';
  2. // https://tc39.github.io/proposal-flatMap/#sec-Array.prototype.flatten
  3. var $export = require('./_export');
  4. var flattenIntoArray = require('./_flatten-into-array');
  5. var toObject = require('./_to-object');
  6. var toLength = require('./_to-length');
  7. var toInteger = require('./_to-integer');
  8. var arraySpeciesCreate = require('./_array-species-create');
  9. $export($export.P, 'Array', {
  10. flatten: function flatten(/* depthArg = 1 */) {
  11. var depthArg = arguments[0];
  12. var O = toObject(this);
  13. var sourceLen = toLength(O.length);
  14. var A = arraySpeciesCreate(O, 0);
  15. flattenIntoArray(A, O, O, sourceLen, 0, depthArg === undefined ? 1 : toInteger(depthArg));
  16. return A;
  17. }
  18. });
  19. require('./_add-to-unscopables')('flatten');