Created
June 5, 2020 13:34
-
-
Save mkamranhamid/25f0ad0ab201d1b4c306e8a5e26356b0 to your computer and use it in GitHub Desktop.
Count minimal number of jumps from position X to Y.
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
// codility test prep questions | |
// A small frog wants to get to the other side of the road. The frog is currently located at position X | |
// and wants to get to a position greater than or equal to Y. The small frog always jumps a fixed distance, D. | |
// Count the minimal number of jumps that the small frog must perform to reach its target. | |
// Given X = 10, Y = 85, D = 30 | |
// the function should return 3 | |
function numberOfFrogJumps(x,y,d){ | |
var distanceRequired = y-x; | |
var jumps = Math.ceil(distanceRequired/30) | |
return jumps | |
} | |
numberOfFrogJumps(10, 85, 30) // returns 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment