Untitled

mail@pastecode.io avatar
unknown
plain_text
5 months ago
1.1 kB
2
Indexable
class VulnerabilityScript {
    constructor(scriptId, dependencies = []) {
      this.scriptId = scriptId;
      this.dependencies = dependencies;
    }
  
    getScriptId() {
      return this.scriptId;
    }
  
    getDependencies() {
      return this.dependencies;
    }
  }
  
  function getExecutionOrder(scripts) {
    const visited = new Set();
    const executionOrder = [];
  
    function visit(script) {
      if (!visited.has(script.scriptId)) {
        visited.add(script.scriptId);
        script.dependencies
          .map(depId => scripts.find(s => s.scriptId === depId))
          .forEach(visit);
        executionOrder.push(script.scriptId);
      }
    }
  
    scripts.forEach(visit);
    return executionOrder;
  }
  
  // Example scripts
  const script1 = new VulnerabilityScript(1, []);
  const script2 = new VulnerabilityScript(2, [1]);
  const script3 = new VulnerabilityScript(3, [2]);
  const script4 = new VulnerabilityScript(4, [2, 3]);
  
  const scripts = [script4, script3, script2, script1];
  
  // Get the execution order
  const order = getExecutionOrder(scripts);
  console.log(order); // Output: [1, 2, 3, 4]
Leave a Comment