Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull Request: Basic App Logic 1 (Milestone 4) #4

Merged
merged 4 commits into from
Jan 15, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
remove shallow obj copy, handle invalid divisor
  • Loading branch information
johnsonsirv committed Jan 14, 2020
commit f3ab60cef795540ed22b61006684ded7c4437d28
9 changes: 5 additions & 4 deletions src/logic/calculate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import operate from './operate';

const calculate = (data, btnName) => {
const temp = data;
let { total } = data;
const { next, operation } = data;
const calcOperations = {
AC: 0,
'+/-': -1,
Expand All @@ -11,12 +12,12 @@ const calculate = (data, btnName) => {
const operations = ['÷', 'x', '-', '+'];

if (calc.includes(btnName)) {
temp.total = data.total * data.next * calcOperations[btnName];
total = total * next * calcOperations[btnName];
}
if (operations.includes(btnName)) {
temp.total = operate(data.total, data.next, btnName);
total = operate(total, next, btnName);
}
return data;
return { total, next, operation };
};

export default calculate;
6 changes: 5 additions & 1 deletion src/logic/operate.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ const operate = (numberOne, numberTwo, operation) => {
const n2 = new Big(numberTwo);
switch (operation) {
case '÷':
result = n1.div(n2);
try {
result = n1.div(n2);
} catch (error) {
result = 'Er';
}
break;
case 'x':
result = n1.times(n2);
Expand Down