Skip to content

Instantly share code, notes, and snippets.

@ricardosaraiva
Created July 3, 2017 21:59
Show Gist options
  • Save ricardosaraiva/ed76477932f470ff51ccbfe0777fb952 to your computer and use it in GitHub Desktop.
Save ricardosaraiva/ed76477932f470ff51ccbfe0777fb952 to your computer and use it in GitHub Desktop.
algoritmo para divisão.
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