Skip to content

Instantly share code, notes, and snippets.

@Stefanacef
Created September 29, 2021 11:06
Show Gist options
  • Save Stefanacef/52514d87e4d3698ddc204c7a1811366f to your computer and use it in GitHub Desktop.
Save Stefanacef/52514d87e4d3698ddc204c7a1811366f to your computer and use it in GitHub Desktop.
Solution for "Number Line Jumps" in Hackerrank
function kangaroo(x1, v1, x2, v2) {
if (x1 > x2) {
if (v1 >= v2) return "NO";
}
if (x2 > x1) {
if (v2 >= v1) return "NO";
}
let jump = (x2 - x1) / (v2 - v1);
return jump % 1 === 0 ? "YES" : "NO";
}
console.log(kangaroo(35, 1, 45, 3));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment