function filter(obj, f, opt_obj) {
  const res = {};
  for (const key in obj) {
    if (f.call(/** @type {?} */ (opt_obj), obj[key], key, obj)) {
      res[key] = obj[key];
    }
  }
  return res;
}
Calls a function for each element in an object/map/hash. If that call returns
true, adds the element to a new object.
@param {?Object<K,V>} obj The object over which to iterate.
@param {function(this:T,V,?,?Object<K,V>):boolean} f The function to call for
    every element. This function takes 3 arguments (the value, the key and
    the object) and should return a boolean. If the return value is true the
    element is added to the result object. If it is false the element is not
    included.
@param {T=} opt_obj This is used as the 'this' object within f.
@return {!Object<K,V>} a new object in which only elements that passed the
    test are present.
@template T,K,V