Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(257)

Unified Diff: tracing/tracing/base/iteration_helpers.html

Issue 2162963002: [polymer] Merge of master into polymer10-migration (Closed) Base URL: git@github.com:catapult-project/catapult.git@polymer10-migration
Patch Set: Merge polymer10-migration int polymer10-merge Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tracing/tracing/base/extension_registry.html ('k') | tracing/tracing/base/math.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tracing/tracing/base/iteration_helpers.html
diff --git a/tracing/tracing/base/iteration_helpers.html b/tracing/tracing/base/iteration_helpers.html
index ddd3a90d43eb469dc266cd3af092138b7cf566b3..09c6519ff25b60e96cb9573caee446fd7447c0b5 100644
--- a/tracing/tracing/base/iteration_helpers.html
+++ b/tracing/tracing/base/iteration_helpers.html
@@ -11,9 +11,10 @@ found in the LICENSE file.
'use strict';
tr.exportTo('tr.b', function() {
+
/**
* Converts any object which is either (a) an iterable, or (b) an
- * "array-ish" obect (has length property and can be indexed into)
+ * "array-ish" object (has length property and can be indexed into)
* into an array.
*/
function asArray(x) {
@@ -173,21 +174,21 @@ tr.exportTo('tr.b', function() {
/**
* Returns a new dictionary with items grouped by the return value of the
* specified function being called on each item.
- * @param {!Array.<Object>} ary The array being iterated through
- * @param {!Function} fn The mapping function between the array value and the
- * map key.
+ * @param {!Array.<!*>} ary The array being iterated through
+ * @param {!function(!*):!*} callback The mapping function between the array
+ * value and the map key.
+ * @param {*=} opt_this
*/
- function group(ary, fn) {
- return ary.reduce(function(accumulator, curr) {
- var key = fn(curr);
-
- if (key in accumulator)
- accumulator[key].push(curr);
+ function group(ary, callback, opt_this) {
+ var results = {};
+ for (var element of ary) {
+ var key = callback.call(opt_this, element);
+ if (key in results)
+ results[key].push(element);
else
- accumulator[key] = [curr];
-
- return accumulator;
- }, {});
+ results[key] = [element];
+ }
+ return results;
}
function iterItems(dict, fn, opt_this) {
« no previous file with comments | « tracing/tracing/base/extension_registry.html ('k') | tracing/tracing/base/math.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698