Jumping on the Clouds: Revisited

  • + 1 comment

    Solution in JavaScript

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