Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function checkIfNumber(symbol){
- if(typeof symbol=="number"){
- return true
- }else{
- return false;
- }
- }
- function add (...items){
- arr=[];
- for (const item of items) {
- if(checkIfNumber(item)!=true) {
- throw new Error(`${item} is not a number`);
- }else{
- arr.push(item);
- }
- }
- const reducer = (accumulator, currentValue) => accumulator + currentValue;
- console.log(arr.reduce(reducer))
- }
- function multy (...items){
- arr=[];
- for (const item of items) {
- if(checkIfNumber(item)!=true) {
- throw new Error(`${item} is not a number`);
- }else{
- arr.push(item);
- }
- }
- const reducer = (accumulator, currentValue) => accumulator * currentValue;
- console.log(arr.reduce(reducer))
- }
- const Calculator = (a,b,...Func) => {
- let arr = [];
- for(const item of Func)
- {
- arr.push(item(a,b));
- }
- return arr;
- };
- try{
- Calculator(2,5,multy,add,add);
- }catch(error)
- {
- console.log(error.message);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement