Skip to content

Instantly share code, notes, and snippets.

@DavidAlejandro18
Created July 30, 2022 06:06
Show Gist options
  • Save DavidAlejandro18/f89036a1d0c85fae06fde90a7517c303 to your computer and use it in GitHub Desktop.
Save DavidAlejandro18/f89036a1d0c85fae06fde90a7517c303 to your computer and use it in GitHub Desktop.
Función que obtiene la unidad imaginaria de una potencia imaginaria
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