Kangaroo Hackerrank Challenge: https://www.hackerrank.com/challenges/kangaroo/problem?isFullScreen=true
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
/* | |
* Complete the 'kangaroo' function below. | |
* | |
* The function is expected to return a STRING. | |
* The function accepts following parameters: | |
* 1. INTEGER x1 | |
* 2. INTEGER v1 | |
* 3. INTEGER x2 | |
* 4. INTEGER v2 | |
*/ | |
function kangaroo(x1, v1, x2, v2) { | |
let result = 'NO'; | |
for (let i = 0; i < 10000; i++) { | |
//calculates the positions of the kangaroos after a given number of jumps and test if the postions are equal | |
if (x1+v1*i === x2+v2*i) { | |
return 'YES'; | |
} | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment