Practice ยท 2 of 2
Break a Circular Import
CHALLENGE
Difficulty: intermediate+25 XP
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.
Press Submit to check your solution.
Back to lesson: Practice: Designing Module Boundaries โ Practice