Created
July 3, 2018 03:25
-
-
Save andhikamaheva/77e4a4bc393b594aa17856528fbe9764 to your computer and use it in GitHub Desktop.
Codility FrogJmp Exercise Solution (JavaScript/NodeJS)
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
// you can write to stdout for debugging purposes, e.g. | |
// console.log('this is a debug message'); | |
function solution(X, Y, D) { | |
// write your code in JavaScript (Node.js 8.9.4) | |
if (X >= Y) { | |
return 0 | |
} else if (X === Y) { | |
return 0 | |
} else if (D >= (Y-X)) { | |
return 1 | |
} else { | |
minimalJumps = parseInt((Y-X) / D) | |
minimalJumps += ((Y-X)%D > 0 ? 1 : 0) | |
return minimalJumps | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A faster and cleaner solution