Created
September 29, 2021 11:06
-
-
Save Stefanacef/52514d87e4d3698ddc204c7a1811366f to your computer and use it in GitHub Desktop.
Solution for "Number Line Jumps" in Hackerrank
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
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