Created
July 3, 2017 21:59
-
-
Save ricardosaraiva/ed76477932f470ff51ccbfe0777fb952 to your computer and use it in GitHub Desktop.
algoritmo para divisão.
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
const div = (valor) => (dividendo) => { | |
let inteiro = 0; | |
let decimal = ''; | |
let i = 0; | |
while (valor >= dividendo) { | |
valor = valor - dividendo; | |
inteiro = inteiro + 1; | |
} | |
while (valor > 0 && decimal < 999999) { | |
i = valor; | |
valor = 0; | |
while (i > 0) { | |
valor = valor + 10; | |
i = i - 1; | |
} | |
i = 0; | |
while (valor >= dividendo) { | |
valor = valor - dividendo; | |
i = i + 1; | |
} | |
decimal = decimal + i.toString(); | |
if(valor == 0) { | |
break; | |
} | |
} | |
return parseFloat(inteiro + '.' + decimal); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment