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

Side by Side Diff: chrome/renderer/resources/extensions/utils.js

Issue 10392127: Move declarative API into events API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix change schema type reference from 'Event' to 'events.Event' Created 8 years, 7 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 function forEach(dict, f) {
6 for (key in dict) {
7 if (dict.hasOwnProperty(key))
8 f(key, dict[key]);
9 }
10 }
11
12 // Assuming |array_of_dictionaries| is structured like this:
13 // [{id: 1, ... }, {id: 2, ...}, ...], you can use
14 // lookup(array_of_dictionaries, 'id', 2) to get the dictionary with id == 2.
15 function lookup(array_of_dictionaries, field, value) {
16 var filter = function (dict) {return dict[field] == value;};
17 var matches = array_of_dictionaries.filter(filter);
18 if (matches.length == 0) {
19 return undefined;
20 } else if (matches.length == 1) {
21 return matches[0]
22 } else {
23 throw new Error("Failed lookup of field '" + field + "' with value '" +
24 value + "'");
25 }
26 }
27
28 exports.forEach = forEach;
29 exports.lookup = lookup;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698