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

Side by Side Diff: tracing/tracing/base/iteration_helpers.html

Issue 2959713003: Remove tr.b.findFirstKeyInDictMatching. (Closed)
Patch Set: rebase Created 3 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 unified diff | Download patch
« no previous file with comments | « no previous file | tracing/tracing/base/iteration_helpers_test.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <!-- 2 <!--
3 Copyright (c) 2014 The Chromium Authors. All rights reserved. 3 Copyright (c) 2014 The Chromium Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style license that can be 4 Use of this source code is governed by a BSD-style license that can be
5 found in the LICENSE file. 5 found in the LICENSE file.
6 --> 6 -->
7 7
8 <link rel="import" href="/tracing/base/base.html"> 8 <link rel="import" href="/tracing/base/base.html">
9 9
10 <script> 10 <script>
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 * element and returns a value that is coerced to a boolean. Defaults to 262 * element and returns a value that is coerced to a boolean. Defaults to
263 * the identity function. 263 * the identity function.
264 * @param {*=} opt_this Optional 'this' context for opt_func. 264 * @param {*=} opt_this Optional 'this' context for opt_func.
265 */ 265 */
266 function findFirstInArray(ary, opt_func, opt_this) { 266 function findFirstInArray(ary, opt_func, opt_this) {
267 const i = findFirstIndexInArray(ary, opt_func, opt_func); 267 const i = findFirstIndexInArray(ary, opt_func, opt_func);
268 if (i === -1) return undefined; 268 if (i === -1) return undefined;
269 return ary[i]; 269 return ary[i];
270 } 270 }
271 271
272 /**
273 * Returns the key of the first dictionary entry for which |opt_func| returns
274 * a truthy value.
275 *
276 * @param {!Object} dict The dictionary being searched.
277 * @param {function(*, *): *=} opt_func The test function which accepts a
278 * dictionary key as its first parameter, the corresponding dictionary
279 * value as its second parameter, and returns a value that is coerced to a
280 * boolean. Defaults to the identity function (which returns the key).
281 * @param {*=} opt_this Optional 'this' context for opt_func.
282 */
283 function findFirstKeyInDictMatching(dict, opt_func, opt_this) {
284 const func = opt_func || (x => x);
285 for (const key in dict) {
286 if (func.call(opt_this, key, dict[key])) {
287 return key;
288 }
289 }
290 return undefined;
291 }
292
293 /** Returns the values in an ES6 Map object. */ 272 /** Returns the values in an ES6 Map object. */
294 function mapValues(map) { 273 function mapValues(map) {
295 const values = []; 274 const values = [];
296 for (const value of map.values()) { 275 for (const value of map.values()) {
297 values.push(value); 276 values.push(value);
298 } 277 }
299 return values; 278 return values;
300 } 279 }
301 280
302 function setsEqual(a, b) { 281 function setsEqual(a, b) {
(...skipping 13 matching lines...) Expand all
316 getOnlyElement, 295 getOnlyElement,
317 getFirstElement, 296 getFirstElement,
318 groupIntoMap, 297 groupIntoMap,
319 mapItems, 298 mapItems,
320 filterItems, 299 filterItems,
321 inPlaceFilter, 300 inPlaceFilter,
322 invertArrayOfDicts, 301 invertArrayOfDicts,
323 arrayToDict, 302 arrayToDict,
324 findFirstIndexInArray, 303 findFirstIndexInArray,
325 findFirstInArray, 304 findFirstInArray,
326 findFirstKeyInDictMatching,
327 mapValues, 305 mapValues,
328 setsEqual, 306 setsEqual,
329 }; 307 };
330 }); 308 });
331 </script> 309 </script>
OLDNEW
« no previous file with comments | « no previous file | tracing/tracing/base/iteration_helpers_test.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698