From 30cb71fd7b7acc1cfd86919add814d2e12ae7eed Mon Sep 17 00:00:00 2001 From: Thalesmar Date: Fri, 22 Aug 2025 05:53:43 +0100 Subject: [PATCH] adding my solution to the project --- Solutions/Thalesmar_solution.js | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Solutions/Thalesmar_solution.js diff --git a/Solutions/Thalesmar_solution.js b/Solutions/Thalesmar_solution.js new file mode 100644 index 0000000..516c661 --- /dev/null +++ b/Solutions/Thalesmar_solution.js @@ -0,0 +1,35 @@ +// Write a function identity that takes an argument and returns that argument +const identity = (x) => x; + +// Write a binary function addb that takes two numbers and returns their sum +const addb = (a, b) => a + b; + +// Write a binary function subb that takes two numbers and returns their difference +const subb = (a, b) => a - b; + +// Write a binary function mulb that takes two numbers and returns their product +const mulb = (a, b) => a * b; + +// Write a binary function minb that takes two numbers and returns the smaller one +const minb = (a, b) => Math.min(a, b); + +// Write a binary function maxb that takes two numbers and returns the larger one +const maxb = (a, b) => Math.max(a, b); + +// Write a function add that is generalized for any amount of arguments +const add = (...nums) => nums.reduce((a, b) => a + b, 0); + +// Write a function sub that is generalized for any amount of arguments +const sub = (...nums) => nums.reduce((a, b) => a - b); + +// Write a function mul that is generalized for any amount of arguments +const mul = (...nums) => nums.reduce((a, b) => a * b, 1); + +// Write a function min that is generalized for any amount of arguments +const min = (...nums) => nums.reduce((a, b) => (a < b ? a : b)); + +// Write a function max that is generalized for any amount of arguments +const max = (...nums) => nums.reduce((a, b) => (a > b ? a : b)); + +// Export all functions +module.exports = { identity, addb, subb, mulb, minb, maxb, add, sub, mul, min, max }; \ No newline at end of file