Piotr Jasiun пре 9 година
родитељ
комит
3b26232f5b
1 измењених фајлова са 18 додато и 0 уклоњено
  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).