-
-
Save parzibyte/b11f693e12a2d33c8f62bc3e0152b788 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
class FraccionMixta { | |
/* | |
https://parzibyte.me/blog | |
*/ | |
constructor(entero, fraccion) { | |
this.entero = entero; | |
this.fraccion = fraccion; | |
} | |
aImpropia() { | |
let numerador = this.fraccion.numerador; | |
if (this.entero) { | |
numerador = numerador + (this.fraccion.denominador * this.entero); | |
} | |
return new Fraccion(numerador, this.fraccion.denominador); | |
} | |
static desdeImpropia(fraccion) { | |
let entero = 0; | |
if (fraccion.numerador >= fraccion.denominador) { | |
entero = Math.floor(fraccion.numerador / fraccion.denominador); | |
const residuo = fraccion.numerador % fraccion.denominador; | |
if (residuo > 0) { | |
fraccion = new Fraccion(residuo, fraccion.denominador); | |
} else { | |
fraccion = null; | |
} | |
} | |
return new FraccionMixta(entero, fraccion); | |
} | |
toString() { | |
let resultado = ""; | |
if (this.entero) { | |
resultado = resultado.concat(this.entero); | |
if (this.fraccion) { | |
resultado = resultado.concat(" + "); | |
} | |
} | |
if (this.fraccion) { | |
resultado = resultado.concat(this.fraccion.toString()); | |
} | |
return resultado; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment