#Bitburner #Games #Snippets September 24, 2023

Bitburner: Primitive Scanner

export async function main(ns) {
  // Create an empty Set to store the merged companies
  let mergedCompanies = new Set();
  
  // Create an array to store the companies that need to be scanned, starting with "home"
  let companiesToScan = ["home"];
  
  // Continue scanning until there are no more companies left to scan
  while (companiesToScan.length > 0) {

    // Get the first company from the list of companies to scan
    const company = companiesToScan.shift();

    // Scan the current company and retrieve the scanned data
    const scannedData = ns.scan(company);

    // Iterate over the scanned data to process each new company
    scannedData.forEach((newCompany) => {

      // Check if the new company is not already in the merged companies set
      if (!mergedCompanies.has(newCompany)) {

        // If it's a new company, add it to the merged companies set
        mergedCompanies.add(newCompany);

        // Also add the new company to the list of companies to scan
        companiesToScan.push(newCompany);
      }
    });
  }
  
  // Print the merged companies set as an array
  ns.tprint([...mergedCompanies]);
}

SEARCH