jumpingOnClouds

    0

    0

    The code jumps on clouds. It loops through the cloud array, looking for a cloud that has a value of 0 in its second position. If found, it increases the value of i by 2, and continues looping. Finally, it increments the jumps variable.

    function jumpingOnClouds(c) {
      let jumps = 0;
      let i = 0;
      while (i < c.length - 1) {
        if (c[i + 2] === 0) {
          i += 2;
        } else {
          i++;
        }
        jumps++;
      }
      return jumps;
    }
    
    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.