viralAdvertising.js

    0

    0

    The viralAdvertising() function will set a shared variable to 5 and then loop through the given number of iterations. Each iteration will increase the shared variable by 1/2 and then add the value of the shared variable to the cumulative variable. The last step will set the shared variable to the cumulative variable.

    
    function viralAdvertising(n) {
      let shared = 5;
      let cumulative = 0;
      let liked = 0;
    
      for (let i = 1; i <= n; i++) {
        liked = Math.floor(shared / 2);
        cumulative += liked;
        shared = liked * 3;
      }
    
      return cumulative;
    }
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.