Explorar o código

Working on...

Piotr Jasiun %!s(int64=9) %!d(string=hai) anos
pai
achega
3b26232f5b
Modificáronse 1 ficheiros con 18 adicións e 0 borrados
  1. 18 0
      packages/ckeditor5-ui/src/utils.js

+ 18 - 0
packages/ckeditor5-ui/src/utils.js

@@ -175,6 +175,24 @@ const utils = {
 		return null;
 	},
 
+	/**
+	 * Returns the number of items return by the iterator.
+	 *
+	 *		utils.count( [ 1, 2, 3, 4, 5 ] ); // 5;
+	 *
+	 * @param {Iterable.<*>} iterator Any iterator.
+	 * @returns {Number} Number of items returned by that iterator.
+	 */
+	count( iterator ) {
+		let count = 0;
+
+		for ( let _ of iterator ) { // jshint ignore:line
+			count++;
+		}
+
+		return count;
+	},
+
 	/**
 	 * Copies enumerable properties and symbols from the objects given as 2nd+ parameters to the
 	 * prototype of first object (a constructor).