Last active
December 18, 2023 14:14
-
-
Save ZackStone/241146636aab47625a97658791e6dd6f to your computer and use it in GitHub Desktop.
Calculadora - Só pode somar
This file contains hidden or 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
var calc = {}; | |
calc.somar = function (x,y) { | |
//console.log(`somando ${x} com ${y}`); | |
return x + y; | |
} | |
calc.multiplicar = function(x ,y) { | |
var resultado = 0; | |
for (var i = 0; i < y; i++) { | |
resultado = calc.somar(resultado, x); | |
} | |
return resultado; | |
} | |
calc.subtrair = function (x,y) { | |
return calc.somar(x, -y); | |
} | |
calc.dividir = function(x, y) { | |
var resultado = 0; | |
while (x >= y) { | |
resultado = calc.somar(resultado, 1); | |
x = calc.subtrair(x, y); | |
} | |
return resultado; | |
} | |
calc.somarLista = function(arr) { | |
var resultado = 0; | |
for (var i = 0; i < arr.length; i++) { | |
resultado = calc.somar(resultado, arr[i]); | |
} | |
return resultado; | |
} | |
calc.calcularMedia = function(arr) { | |
var resultado = calc.somarLista(arr); | |
return calc.dividir(resultado, arr.length); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment