A linter checks a project for circular imports. imports is an object that maps a file name to the list of file names it imports, such as { "app.js": ["api.js"] }. A file that imports nothing may be missing from the object.
Write hasCircularImport(imports) that returns true if some file can reach itself by following imports (including a file that imports itself), and false otherwise.
Input: imports = {"a.js":["b.js"],"b.js":["c.js"],"c.js":["a.js"]} Output: true
a.js → b.js → c.js → a.js goes in a circle.
Input: imports = {"app.js":["utils.js","api.js"],"api.js":["utils.js"]} Output: false
utils.js is reached twice, but nothing leads back to a file on the current path.
10000 keys.50000 imports in total.Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #447 Find a Circular Import. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.