BFS = (start, callback) => {
  const visited = new Set();
  /** @type {{ key: string, value: any }[][]} */
  let toVisit = [
    [{ key: null, value: start }]
  ];

  callback(toVisit[0]);

  while (toVisit.length > 0) {
    /** @type {{ key: string, value: any }[][]} */
    const newToVisit = [];

    for (const path of toVisit) {
      const obj = path[path.length - 1].value;
      if (!visited.has(obj)) {
        visited.add(obj);

        for (const key in obj) {
          const value = obj[key];

          path.push({ key, value });
          callback(path);

          if (Array.isArray(value) || Object.prototype.toString.call(value) === '[object Object]') {
            newToVisit.push([...path]);
          }

          path.pop();
        }
      }
    }

    toVisit = newToVisit;
  }
}
Performs a breadth-first search on the given start element.

@param {any} start
@param {(path: { key: string, value: any }[]) => void} callback