Skip to content

Instantly share code, notes, and snippets.

@davidjsalazarmoreno
Created March 18, 2021 21:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidjsalazarmoreno/ad4437b6f80b6b7a5e0777e7a3552c4b to your computer and use it in GitHub Desktop.
Save davidjsalazarmoreno/ad4437b6f80b6b7a5e0777e7a3552c4b to your computer and use it in GitHub Desktop.
function jumpingOnClouds(arr) {
const length = arr.length;
let jumps = 0;
for(let i = 0; i <= length; i++) {
const canIJumpTwoClouds = arr[i + 2] === 0;
if (canIJumpTwoClouds) {
jumps += 1;
i += 1;
continue;
}
const canIJumpOneCloud = arr[i + 1] === 0;
if (canIJumpOneCloud) {
jumps += 1;
}
}
return jumps;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment