Jumping on the Clouds: Revisited

  • + 0 comments

    Answer in javascript

    function jumpingOnClouds(c, k) {
      let energy = 100;
      let cloud = 0;
    
      const jump = () => {
        cloud = (cloud + k) % c.length;
        energy -= 1;
        if (c[cloud]) energy -= 2;
      };
    
      do {
        jump();
      } while (cloud != 0);
    
      return energy;
    }