utopianTree.js

    0

    0

    The following code creates an "utopian tree" that grows faster the more often it is cycled. The function creates a loop that keeps track of the cycle number, as well as the height of the tree. The code cycles through the loop at a rate of 1 per 2.

    function utopianTree(n) {
    let cycle = 1;
      let height = 1;
      
      while (cycle <= n){
        if(cycle % 2 !== 0 ){
          height *= 2;
        }else{
          height++;
        }
        cycle++;
      }
      
      return height;
    }
    
    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.