Skip to content

Instantly share code, notes, and snippets.

@jeyziel
Created September 4, 2017 00:15
Show Gist options
  • Save jeyziel/32a32f44739f7733006458df881389d2 to your computer and use it in GitHub Desktop.
Save jeyziel/32a32f44739f7733006458df881389d2 to your computer and use it in GitHub Desktop.
Desafio da divisão
const add = ( x ) => ( y ) => x + y
const divide = ( x ) => ( y ) => {
let multiplyfor10 = 0;
const multiply10 = add(10)
const decrement1 = add(-1)
const addFinal = add(0.1)
const decrementY = add(-y)
let resultFinal = 0
while ( x > 0 ) {
multiplyfor10 = multiply10(multiplyfor10)
x = decrement1(x)
}
while ( multiplyfor10 > 0) {
multiplyfor10 = decrementY(multiplyfor10)
resultFinal = addFinal(resultFinal)
}
return resultFinal.toFixed(1)
}
console.log( divide(5)(2) ) // 5 * 10 = 50 | 50 / 2 = 25 | 25 * 0.1 = 2.5
console.log( divide(7)(2) )
//pertecem ao conjunto dos numeros racionais decimais.
@suissa
Copy link

suissa commented Sep 7, 2017

Boaaaa!

Depois lhe mostro uma implementação antiga minha usando notação científica ehhehehe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment