implementation.js 758 B

1234567891011121314151617181920212223242526
  1. 'use strict';
  2. var ArraySpeciesCreate = require('es-abstract/2020/ArraySpeciesCreate');
  3. var FlattenIntoArray = require('es-abstract/2020/FlattenIntoArray');
  4. var Get = require('es-abstract/2020/Get');
  5. var IsCallable = require('es-abstract/2020/IsCallable');
  6. var ToLength = require('es-abstract/2020/ToLength');
  7. var ToObject = require('es-abstract/2020/ToObject');
  8. module.exports = function flatMap(mapperFunction) {
  9. var O = ToObject(this);
  10. var sourceLen = ToLength(Get(O, 'length'));
  11. if (!IsCallable(mapperFunction)) {
  12. throw new TypeError('mapperFunction must be a function');
  13. }
  14. var T;
  15. if (arguments.length > 1) {
  16. T = arguments[1];
  17. }
  18. var A = ArraySpeciesCreate(O, 0);
  19. FlattenIntoArray(A, O, sourceLen, 0, 1, mapperFunction, T);
  20. return A;
  21. };