Skip to main content

Practice ยท 2 of 2

Break a Circular Import

Two modules depend on each other: user.js needs formatName, and format.js needs getUser. Write extractShared(code) โ€” given a string describing the two modules, return the name of the piece that should move to a third shared module. Actually, simpler and more real: write findCycle(graph) that detects a circular dependency. graph is an object mapping module name to an array of names it imports. Return true if any cycle exists, false otherwise.

Difficulty: intermediate

Back to lesson: Practice: Designing Module Boundaries โ€” Practice