From 898323c8ecd173988bb2dae7970448d888fd59df Mon Sep 17 00:00:00 2001 From: Xros3x <100667720+Xros3x@users.noreply.github.com> Date: Thu, 14 Sep 2023 08:24:19 -0500 Subject: [PATCH] Adding solutions --- Solutions/Xrose3x_solutions.js | 62 ++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 Solutions/Xrose3x_solutions.js diff --git a/Solutions/Xrose3x_solutions.js b/Solutions/Xrose3x_solutions.js new file mode 100644 index 0000000..b16fbd2 --- /dev/null +++ b/Solutions/Xrose3x_solutions.js @@ -0,0 +1,62 @@ + +//Identity +const indentity = (x) => x; + +//Add +const addb = (a, b) => a + b; + +//Sub +const subb = (a, b) => a - b; + +//Mulb +const mulb = (a, b) => a * b; + +//Minb +const minb = (a, b) => (a < b ? a : b); + +//Maxb +const maxb = (a, b) => (a > b ? a : b); + +//Add (nums) +function add(...args) { + let total = 0; + for (let num of args) { + total += num; + } + return total; +} + +//Sub (nums) +function sub(...args) { + if (args.length === 0) { + throw new Error("At least one argument is required."); + } + + return args.reduce((accumulator, currentValue) => accumulator - currentValue); +} + +//Mul (nums) +function mul(...args) { + if (args.length === 0) { + throw new Error("At least one argument is required."); + } + + return args.reduce((accumulator, currentValue) => accumulator - currentValue); +} + +//Min (nums) +function min(...args) { + if (args.length === 0) { + throw new Error("At least one argument is required."); + } + + let minValue = args[0]; + for (let i = 1; i < args.length; i++) { + if (args[i] < minValue) { + minValue = args[i]; + } + } + return minValue; +} + +//Max (nums) \ No newline at end of file