function eachElement(elements, fn, depth) {

  depth = depth || 0;

  if (!isArray(elements)) {
    elements = [ elements ];
  }

  forEach(elements, function(s, i) {
    var filter = fn(s, i, depth);

    if (isArray(filter) && filter.length) {
      eachElement(filter, fn, depth + 1);
    }
  });
}
Iterate over each element in a collection, calling the iterator function `fn`
with (element, index, recursionDepth).

Recurse into all elements that are returned by `fn`.

@param {Element|Element[]} elements
@param {(element: Element, index: number, depth: number) => Element[] | boolean | undefined} fn
@param {number} [depth] maximum recursion depth