count.js 544 B

1234567891011121314151617181920212223242526
  1. /**
  2. * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /**
  6. * @module utils/count
  7. */
  8. /**
  9. * Returns the number of items return by the iterator.
  10. *
  11. * count( [ 1, 2, 3, 4, 5 ] ); // 5;
  12. *
  13. * @param {Iterable.<*>} iterator Any iterator.
  14. * @returns {Number} Number of items returned by that iterator.
  15. */
  16. export default function count( iterator ) {
  17. let count = 0;
  18. for ( const _ of iterator ) { // eslint-disable-line no-unused-vars
  19. count++;
  20. }
  21. return count;
  22. }