OLD | NEW |
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 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 const result = {}; | 256 const result = {}; |
257 const length = array.length; | 257 const length = array.length; |
258 for (let i = 0; i < length; i++) { | 258 for (let i = 0; i < length; i++) { |
259 const value = array[i]; | 259 const value = array[i]; |
260 const key = valueToKeyFn.call(opt_this, value); | 260 const key = valueToKeyFn.call(opt_this, value); |
261 result[key] = value; | 261 result[key] = value; |
262 } | 262 } |
263 return result; | 263 return result; |
264 } | 264 } |
265 | 265 |
266 /** Returns the value passed in. */ | |
267 function identity(d) { | |
268 return d; | |
269 } | |
270 | |
271 /** | 266 /** |
272 * Returns the index of the first element in |ary| for which |opt_func| | 267 * Returns the index of the first element in |ary| for which |opt_func| |
273 * returns a truthy value. | 268 * returns a truthy value. |
274 * | 269 * |
275 * @param {!Array} ary The array being searched | 270 * @param {!Array} ary The array being searched |
276 * @param {function(*): *=} opt_func The test function which accepts an array | 271 * @param {function(*): *=} opt_func The test function which accepts an array |
277 * element and returns a value that is coerced to a boolean. Defaults to | 272 * element and returns a value that is coerced to a boolean. Defaults to |
278 * the identity function. | 273 * the identity function. |
279 * @param {*=} opt_this Optional 'this' context for opt_func. | 274 * @param {*=} opt_this Optional 'this' context for opt_func. |
280 */ | 275 */ |
281 function findFirstIndexInArray(ary, opt_func, opt_this) { | 276 function findFirstIndexInArray(ary, opt_func, opt_this) { |
282 const func = opt_func || identity; | 277 const func = opt_func || (x => x); |
283 for (let i = 0; i < ary.length; i++) { | 278 for (let i = 0; i < ary.length; i++) { |
284 if (func.call(opt_this, ary[i], i)) return i; | 279 if (func.call(opt_this, ary[i], i)) return i; |
285 } | 280 } |
286 return -1; | 281 return -1; |
287 } | 282 } |
288 | 283 |
289 /** | 284 /** |
290 * Returns the value of the first element in |ary| for which |opt_func| | 285 * Returns the value of the first element in |ary| for which |opt_func| |
291 * returns a truthy value. | 286 * returns a truthy value. |
292 * | 287 * |
(...skipping 14 matching lines...) Expand all Loading... |
307 * a truthy value. | 302 * a truthy value. |
308 * | 303 * |
309 * @param {!Object} dict The dictionary being searched. | 304 * @param {!Object} dict The dictionary being searched. |
310 * @param {function(*, *): *=} opt_func The test function which accepts a | 305 * @param {function(*, *): *=} opt_func The test function which accepts a |
311 * dictionary key as its first parameter, the corresponding dictionary | 306 * dictionary key as its first parameter, the corresponding dictionary |
312 * value as its second parameter, and returns a value that is coerced to a | 307 * value as its second parameter, and returns a value that is coerced to a |
313 * boolean. Defaults to the identity function (which returns the key). | 308 * boolean. Defaults to the identity function (which returns the key). |
314 * @param {*=} opt_this Optional 'this' context for opt_func. | 309 * @param {*=} opt_this Optional 'this' context for opt_func. |
315 */ | 310 */ |
316 function findFirstKeyInDictMatching(dict, opt_func, opt_this) { | 311 function findFirstKeyInDictMatching(dict, opt_func, opt_this) { |
317 const func = opt_func || identity; | 312 const func = opt_func || (x => x); |
318 for (const key in dict) { | 313 for (const key in dict) { |
319 if (func.call(opt_this, key, dict[key])) { | 314 if (func.call(opt_this, key, dict[key])) { |
320 return key; | 315 return key; |
321 } | 316 } |
322 } | 317 } |
323 return undefined; | 318 return undefined; |
324 } | 319 } |
325 | 320 |
326 /** Returns the values in an ES6 Map object. */ | 321 /** Returns the values in an ES6 Map object. */ |
327 function mapValues(map) { | 322 function mapValues(map) { |
(...skipping 21 matching lines...) Expand all Loading... |
349 comparePossiblyUndefinedValues, | 344 comparePossiblyUndefinedValues, |
350 dictionaryContainsValue, | 345 dictionaryContainsValue, |
351 getOnlyElement, | 346 getOnlyElement, |
352 getFirstElement, | 347 getFirstElement, |
353 groupIntoMap, | 348 groupIntoMap, |
354 mapItems, | 349 mapItems, |
355 filterItems, | 350 filterItems, |
356 inPlaceFilter, | 351 inPlaceFilter, |
357 invertArrayOfDicts, | 352 invertArrayOfDicts, |
358 arrayToDict, | 353 arrayToDict, |
359 identity, | |
360 findFirstIndexInArray, | 354 findFirstIndexInArray, |
361 findFirstInArray, | 355 findFirstInArray, |
362 findFirstKeyInDictMatching, | 356 findFirstKeyInDictMatching, |
363 mapValues, | 357 mapValues, |
364 setsEqual, | 358 setsEqual, |
365 }; | 359 }; |
366 }); | 360 }); |
367 </script> | 361 </script> |
OLD | NEW |