Skip to content

Instantly share code, notes, and snippets.

@Nasah-Kuma
Last active September 16, 2022 13:11
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 Nasah-Kuma/6ed966cea7a4652f140f92fd53e264de to your computer and use it in GitHub Desktop.
Save Nasah-Kuma/6ed966cea7a4652f140f92fd53e264de to your computer and use it in GitHub Desktop.
/*
* 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