Created
July 30, 2022 06:06
-
-
Save DavidAlejandro18/f89036a1d0c85fae06fde90a7517c303 to your computer and use it in GitHub Desktop.
Función que obtiene la unidad imaginaria de una potencia imaginaria
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 getUnidadImaginaria(potencia) { | |
let potenciasImaginarias = { | |
0: '1', | |
1: 'i', | |
2: '-1', | |
3: '-i', | |
4: '1' | |
}; | |
let restante = 0; | |
while ((potencia % 4) != 0) { | |
potencia--; | |
restante++; | |
} | |
return potenciasImaginarias[restante]; | |
} | |
// getUnidadImaginaria(100); (1) | |
// getUnidadImaginaria(501); (i) | |
// getUnidadImaginaria(123); (-i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment