Created
April 4, 2018 04:57
-
-
Save parzibyte/a2b2211eecfeb5d93e603834a2bcb482 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
function obtenerSiguienteCuadradoPerfecto(cuadradoPerfecto){ | |
// Obtener su raíz | |
var raiz = Math.sqrt(cuadradoPerfecto); | |
// Comparar si su raíz es un número entero | |
if (raiz === parseInt(raiz)) { | |
/* | |
En caso de que sí, entonces calculamos el siguiente cuadrado perfecto. | |
Para sacarlo, sumamos el cuadrado perfecto + la raíz del siguiente multiplicada por 2. Y a eso le restamos uno. | |
*/ | |
var siguientecuadradoPerfecto = cuadradoPerfecto + ( (raiz + 1) * 2 ) - 1; | |
return siguientecuadradoPerfecto; | |
}else{ | |
// Si no, entonces no era un cuadrado perfecto | |
return -1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment