Junior — Senior
Determining the presence of cyclic dependencies in a file graph
livecode
Task condition
Implement the function hasCircularDependency that checks whether there is a cycle in the dependency graph between files.
type Resource = string;
type Vector = Record<Resource, Resource[]>;
function hasCircularDependency(entrypoint: Resource, deps: Vector): boolean {
// your code here
}
// example
console.warn(hasCircularDependency('index.js', {
'index.js': ['foo.js', 'bar.js'],
'bar.js': ['baz.js'],
'foo.js': ['baz.js'],
'baz.js': ['x.js'],
'x.js': ['foo.js'] // cycle: index → foo → baz → x → foo
})); // true