Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. 'use strict';
  2. var hasSymbols = require('has-symbols')();
  3. var GetIntrinsic = require('../GetIntrinsic');
  4. var callBound = require('./callBound');
  5. var $iterator = GetIntrinsic('%Symbol.iterator%', true);
  6. var $arraySlice = callBound('Array.prototype.slice');
  7. var $arrayJoin = callBound('Array.prototype.join');
  8. module.exports = function getIteratorMethod(ES, iterable) {
  9. var usingIterator;
  10. if (hasSymbols) {
  11. usingIterator = ES.GetMethod(iterable, $iterator);
  12. } else if (ES.IsArray(iterable)) {
  13. usingIterator = function () {
  14. var i = -1;
  15. var arr = this; // eslint-disable-line no-invalid-this
  16. return {
  17. next: function () {
  18. i += 1;
  19. return {
  20. done: i >= arr.length,
  21. value: arr[i]
  22. };
  23. }
  24. };
  25. };
  26. } else if (ES.Type(iterable) === 'String') {
  27. usingIterator = function () {
  28. var i = 0;
  29. return {
  30. next: function () {
  31. var nextIndex = ES.AdvanceStringIndex(iterable, i, true);
  32. var value = $arrayJoin($arraySlice(iterable, i, nextIndex), '');
  33. i = nextIndex;
  34. return {
  35. done: nextIndex > iterable.length,
  36. value: value
  37. };
  38. }
  39. };
  40. };
  41. }
  42. return usingIterator;
  43. };