function count(arr, f, opt_obj) {
  let count = 0;
  forEach(arr, function(element, index, arr) {
    if (f.call(/** @type {?} */ (opt_obj), element, index, arr)) {
      ++count;
    }
  }, opt_obj);
  return count;
}
Counts the array elements that fulfill the predicate, i.e. for which the
callback function returns true. Skips holes in the array.

@param {!IArrayLike<T>|string} arr Array or array like object
    over which to iterate.
@param {function(this: S, T, number, ?): boolean} f The function to call for
    every element. Takes 3 arguments (the element, the index and the array).
@param {S=} opt_obj The object to be used as the value of 'this' within f.
@return {number} The number of the matching elements.
@template T,S