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

Adding solutions #234

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
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
62 changes: 62 additions & 0 deletions Solutions/Xrose3x_solutions.js
Original file line number Diff line number Diff line change
@@ -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)