Skip to content

Commit 6af349b

Browse files
committed
feat(ui): swap equals and power buttons in calculator layout
1 parent da3e594 commit 6af349b

2 files changed

Lines changed: 170 additions & 152 deletions

File tree

api/controller.js

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
'use strict';
1+
"use strict";
22

3-
exports.calculate = function(req, res) {
4-
req.app.use(function(err, _req, res, next) {
3+
exports.calculate = function (req, res) {
4+
req.app.use(function (err, _req, res, next) {
55
if (res.headersSent) {
66
return next(err);
77
}
@@ -11,10 +11,21 @@ exports.calculate = function(req, res) {
1111
});
1212

1313
var operations = {
14-
'add': function(a, b) { return Number(a) + Number(b) },
15-
'subtract': function(a, b) { return a - b },
16-
'multiply': function(a, b) { return a * b },
17-
'divide': function(a, b) { return a / b },
14+
add: function (a, b) {
15+
return Number(a) + Number(b);
16+
},
17+
subtract: function (a, b) {
18+
return a - b;
19+
},
20+
multiply: function (a, b) {
21+
return a * b;
22+
},
23+
divide: function (a, b) {
24+
return a / b;
25+
},
26+
power: function (a, b) {
27+
return Math.pow(a, b);
28+
},
1829
};
1930

2031
if (!req.query.operation) {
@@ -27,15 +38,19 @@ exports.calculate = function(req, res) {
2738
throw new Error("Invalid operation: " + req.query.operation);
2839
}
2940

30-
if (!req.query.operand1 ||
31-
!req.query.operand1.match(/^(-)?[0-9\.]+(e(-)?[0-9]+)?$/) ||
32-
req.query.operand1.replace(/[-0-9e]/g, '').length > 1) {
41+
if (
42+
!req.query.operand1 ||
43+
!req.query.operand1.match(/^(-)?[0-9\.]+(e(-)?[0-9]+)?$/) ||
44+
req.query.operand1.replace(/[-0-9e]/g, "").length > 1
45+
) {
3346
throw new Error("Invalid operand1: " + req.query.operand1);
3447
}
3548

36-
if (!req.query.operand2 ||
37-
!req.query.operand2.match(/^(-)?[0-9\.]+(e(-)?[0-9]+)?$/) ||
38-
req.query.operand2.replace(/[-0-9e]/g, '').length > 1) {
49+
if (
50+
!req.query.operand2 ||
51+
!req.query.operand2.match(/^(-)?[0-9\.]+(e(-)?[0-9]+)?$/) ||
52+
req.query.operand2.replace(/[-0-9e]/g, "").length > 1
53+
) {
3954
throw new Error("Invalid operand2: " + req.query.operand2);
4055
}
4156

0 commit comments

Comments
 (0)