Last active
April 15, 2019 05:07
-
-
Save BrunoDSouza/79034c21f0314a1a73a861c7aa08ab41 to your computer and use it in GitHub Desktop.
Basic Operations on Js
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
function divisao(dividendo, divisor){ | |
var quociente = 0; | |
var resto = 0; | |
while(dividendo > 0 && dividendo >= divisor){ | |
quociente = soma(quociente, 1); | |
dividendo = subtrair(dividendo, divisor); | |
} | |
resto = dividendo; | |
return {quociente, resto} | |
} |
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
function multiplica(multiplicando, multiplicador){ | |
var produto = 0; | |
for(var x = 0; x<multiplicador; x++;){ | |
produto = soma(produto, multiplicando); | |
} | |
return produto; | |
} |
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
function soma(parcela = 0, parcela2 = 0){ | |
return parcela + parcela2 | |
} |
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
function subtrair(minuendo = 0, subtraendo = 0){ | |
return soma(minuendo, soma(~subtraendo, 1)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment