index.js
function visit(item, cycle) {
    let visitedDeps = visited.get(item);

    // Create an object for the item to mark visited deps.
    if (!visitedDeps) {
      visitedDeps = [];
      visited.set(item, visitedDeps);
    }

    // Get the current deps for the item.
    let deps = currDepsMap.get(item);
    if (typeof deps === 'undefined') return;

    // For each dep,
    for (let dep of deps) {
      // Check if this dep creates a cycle. We know it's a cycle if the first
      // item is the same as our dep.
      if (cycle[0] === dep) {
        cycles.push(cycle);
      }

      // If an item hasn't been visited, visit it (and pass an updated
      // potential cycle)
      if (!arrayIncludes(visitedDeps, dep)) {
        visitedDeps.push(dep);
        visit(dep, cycle.concat(dep));
      }
    }
  }
function visit(item, cycle) {
    let visitedDeps = visited.get(item);

    // Create an object for the item to mark visited deps.
    if (!visitedDeps) {
      visitedDeps = [];
      visited.set(item, visitedDeps);
    }

    // Get the current deps for the item.
    let deps = currDepsMap.get(item);
    if (typeof deps === 'undefined') return;

    // For each dep,
    for (let dep of deps) {
      // Check if this dep creates a cycle. We know it's a cycle if the first
      // item is the same as our dep.
      if (cycle[0] === dep) {
        cycles.push(cycle);
      }

      // If an item hasn't been visited, visit it (and pass an updated
      // potential cycle)
      if (!arrayIncludes(visitedDeps, dep)) {
        visitedDeps.push(dep);
        visit(dep, cycle.concat(dep));
      }
    }
  }
function visit ( item , cycle ) { let visitedDeps = visited . get ( item ) ; // Create an object for the item to mark visited deps. if ( ! visitedDeps ) { visitedDeps = [ ] ; visited . set ( item , visitedDeps ) ; } // Get the current deps for the item. let deps = currDepsMap . get ( item ) ; if ( typeof deps === 'undefined' ) return ; // For each dep, for ( let dep of deps ) { // Check if this dep creates a cycle. We know it's a cycle if the first // item is the same as our dep. if ( cycle [ 0 ] === dep ) { cycles . push ( cycle ) ; } // If an item hasn't been visited, visit it (and pass an updated // potential cycle) if ( ! arrayIncludes ( visitedDeps , dep ) ) { visitedDeps . push ( dep ) ; visit ( dep , cycle . concat ( dep ) ) ; } } }
Create a function to call recursively in a depth-first search.
Create a function to call recursively in a depth - first search .