JavaScript: Dependency track

Last update: 10 Dec 23:20
0
Students

Dependency management is always a cornerstone of software development. Usually, programs involve a lot of third-party components, which, in turn, can also rely on third-party components. One of the tasks of the dependency manager is to connect dependencies in the correct order. Libraries that others depend on should be connected earlier. Determining this order is reduced to the graph sorting problem.

sortDeps.js

Implement and export as default a function that takes a list of dependencies as input and returns a list (array) of sorted nodes.

Examples

const deps1 = {
  mongo: [],
  tzinfo: ['thread_safe'],
  uglifier: ['execjs'],
  execjs: ['thread_safe', 'json'],
  redis: [],
};

console.log(sortDeps(deps1));
// => ['mongo', 'thread_safe', 'tzinfo', 'json', 'execjs', 'uglifier', 'redis'];

Independent libraries and library chains should be in the order corresponding to that of the elements in the dependency graph.

Tips

For full access to the challenge you need a professional subscription.

A professional subscription will give you full access to all Hexlet courses, projects and lifetime access to the theory of lessons learned. You can cancel your subscription at any time.

Get access
130
courses
1000
exercises
2000+
hours of theory
3200
tests