Created
March 18, 2021 21:40
-
-
Save davidjsalazarmoreno/ad4437b6f80b6b7a5e0777e7a3552c4b to your computer and use it in GitHub Desktop.
Posible solution for https://www.hackerrank.com/challenges/jumping-on-the-clouds/problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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