From af0ff8381d748e28d08c0eef73ca6ca97da8d6b0 Mon Sep 17 00:00:00 2001 From: Clara Tersi Date: Wed, 24 Jul 2019 19:43:13 -0300 Subject: [PATCH] implemented simple operations --- src/operations/add.js | 5 +++++ src/operations/divide.js | 8 ++++++++ src/operations/index.js | 11 +++++++++++ src/operations/multiply.js | 5 +++++ src/operations/subtract.js | 5 +++++ 5 files changed, 34 insertions(+) create mode 100644 src/operations/add.js create mode 100644 src/operations/divide.js create mode 100644 src/operations/index.js create mode 100644 src/operations/multiply.js create mode 100644 src/operations/subtract.js diff --git a/src/operations/add.js b/src/operations/add.js new file mode 100644 index 0000000..2112af5 --- /dev/null +++ b/src/operations/add.js @@ -0,0 +1,5 @@ +const add = (addend1, addend2) => { + return addend1 + addend2; +}; + +module.exports = add; \ No newline at end of file diff --git a/src/operations/divide.js b/src/operations/divide.js new file mode 100644 index 0000000..f76d627 --- /dev/null +++ b/src/operations/divide.js @@ -0,0 +1,8 @@ +const divide = (dividend, divisor) => { + if (divisor === 0) { + throw new Error('Cannot divide by 0'); + } + return dividend / divisor; +}; + +module.exports = divide; \ No newline at end of file diff --git a/src/operations/index.js b/src/operations/index.js new file mode 100644 index 0000000..d36a775 --- /dev/null +++ b/src/operations/index.js @@ -0,0 +1,11 @@ +const add = require('./add'); +const divide = require('./divide'); +const multiply = require('./multiply'); +const subtract = require('./subtract'); + +module.exports = { + add, + divide, + multiply, + subtract, +}; \ No newline at end of file diff --git a/src/operations/multiply.js b/src/operations/multiply.js new file mode 100644 index 0000000..f2ae784 --- /dev/null +++ b/src/operations/multiply.js @@ -0,0 +1,5 @@ +const multiply = (multiplicand, multiplier) => { + return multiplicand * multiplier; +}; + +module.exports = multiply; \ No newline at end of file diff --git a/src/operations/subtract.js b/src/operations/subtract.js new file mode 100644 index 0000000..294c4ab --- /dev/null +++ b/src/operations/subtract.js @@ -0,0 +1,5 @@ +const subtract = (minuend, subtrahend) => { + return minuend - subtrahend; +}; + +module.exports = subtract; \ No newline at end of file