Created
August 16, 2019 01:14
-
-
Save edo9k/d52956b914b0bc3a3d63153238347f10 to your computer and use it in GitHub Desktop.
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
calc = (a, b, op) => operations[op](a,b) | |
operations = { | |
'+': (a, b) => a + b, | |
'-': (a, b) => a - b, | |
'*': (a, b) => a * b, | |
'/': (a, b) => a / b | |
} |
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
calc = (a, b, op) => { | |
switch (op) { | |
case '+': | |
return a + b | |
break | |
case '-': | |
return a - b | |
break | |
case '*': | |
return a * b | |
break | |
case '/': | |
return a / b | |
break | |
} | |
} |
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
/* my fancy test suite */ | |
const expect = (fn, input, description, expected) => { | |
const result = fn(...input); | |
(result === expected) | |
? console.log(`passou :: ${description} :: esperava ${expected}, recebeu ${result}`) | |
: console.error(`deu ruim :: ${description} :: esperava ${expected}, recebeu ${result}`) | |
} | |
/* so-called tests */ | |
rodaTestes = () => { | |
console.clear() | |
expect(calc, [1,1, '+'], 'tenta somar dois numeros', 2) | |
expect(calc, [1,1, '-'], 'tenta subtrair dois numeros', 0) | |
expect(calc, [2,2, '*'], 'tenta multiplicar dois numeros', 4) | |
expect(calc, [3,3, '/'], 'tenta dividir um numero pelo outro', 1) | |
} | |
/* behold the codigo */ | |
calc = (a, b, op) => { | |
switch (op) { | |
case '+': | |
return a + b | |
break | |
case '-': | |
return a - b | |
break | |
case '*': | |
return a * b | |
break | |
case '/': | |
return a / b | |
break | |
} | |
} | |
calc_json = (a, b, op) => operations[op](a,b) | |
operations = { | |
'+': (a, b) => a + b, | |
'-': (a, b) => a - b, | |
'*': (a, b) => a * b, | |
'/': (a, b) => a / b | |
} | |
/* roda testes */ | |
rodaTestes() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment