implementation.js 725 B

12345678910111213141516171819202122
  1. 'use strict';
  2. var ArraySpeciesCreate = require('es-abstract/2023/ArraySpeciesCreate');
  3. var FlattenIntoArray = require('es-abstract/2023/FlattenIntoArray');
  4. var Get = require('es-abstract/2023/Get');
  5. var ToIntegerOrInfinity = require('es-abstract/2023/ToIntegerOrInfinity');
  6. var ToLength = require('es-abstract/2023/ToLength');
  7. var ToObject = require('es-abstract/2023/ToObject');
  8. module.exports = function flat() {
  9. var O = ToObject(this);
  10. var sourceLen = ToLength(Get(O, 'length'));
  11. var depthNum = 1;
  12. if (arguments.length > 0 && typeof arguments[0] !== 'undefined') {
  13. depthNum = ToIntegerOrInfinity(arguments[0]);
  14. }
  15. var A = ArraySpeciesCreate(O, 0);
  16. FlattenIntoArray(A, O, sourceLen, 0, depthNum);
  17. return A;
  18. };