Back to tasksGet help with live coding in real time with Sobes Copilot
Junior — Senior
23
Определение наличия циклических зависимостей в графе файлов
Task condition
Реализуйте функцию hasCircularDependency, которая проверяет, присутствует ли цикл в графе зависимостей между файлами.
type Resource = string;
type Vector = Record<Resource, Resource[]>;
function hasCircularDependency(entrypoint: Resource, deps: Vector): boolean {
// ваш код тут
}
// пример
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'] // цикл: index → foo → baz → x → foo
})); // true