Created
September 4, 2017 00:15
-
-
Save jeyziel/32a32f44739f7733006458df881389d2 to your computer and use it in GitHub Desktop.
Desafio da 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 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. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Boaaaa!
Depois lhe mostro uma implementação antiga minha usando notação científica ehhehehe