я тут немного пофантазировал...
function isNum(pretendent) {
return typeof pretendent === "number" && !Number.isNaN(pretendent);
}
function validate(list) {
if( list.every( (item) => isNum(item) ) ) {
return true;
}
console.log('All provided arguments should be numbers!');
return false;
}
const operations = {
addTwo: (a, b) => a + b,
substractTwo: (a, b) => a - b,
divideTwo: (a, b) => a / b,
multiplyTwo: (a, b) => a * b
};
function take(fNum) {
if ( !isNum(fNum) ) {
console.log('You are supposed to provide number!');
return;
}
return {
add: (...args) => validate(args) && args.reduce(operations.addTwo, fNum),
substract: (...args) => validate(args) && args.reduce(operations.substractTwo, fNum),
divide: (...args) => validate(args) && args.reduce(operations.divideTwo, fNum),
multiply: (...args) => validate(args) && args.reduce(operations.multiplyTwo, fNum)
};
}
https://repl.it/ID7B