-
-
Save parzibyte/5f94453760d9357f935324141ea8541a to your computer and use it in GitHub Desktop.
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
/** | |
* El elevador más cercano con JS | |
* | |
* @author parzibyte | |
*/ | |
const elevadorMasCercano = (ubicacionDelIzquierdo, ubicacionDelDerecho, pisoDesdeDondeSeLlama) => | |
Math.abs(pisoDesdeDondeSeLlama - ubicacionDelIzquierdo) < Math.abs(pisoDesdeDondeSeLlama - ubicacionDelDerecho) ? "izquierda" : "derecha"; | |
// Probemos... | |
console.log(elevadorMasCercano(1, 2, 0)); // Debería ser izquierda | |
console.log(elevadorMasCercano(1, 1, 2)); // Debería ser derecha porque tienen la misma distancia | |
console.log(elevadorMasCercano(0, 2, 1)); // Debería ser derecha porque tienen la misma distancia | |
console.log(elevadorMasCercano(0, 2, 0)); // Debería ser izquierda | |
console.log(elevadorMasCercano(2, 1, 1)); // Debería ser derecha |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment