function combine(){
//console.log(arguments)
let result;
let errors=[];
let newError;
iterations: for( let i = 0 ; i < arguments.length; i++){
if(typeof arguments[i]!=='function'){
throw new Error('Each argument must be a function!')
}else{
try {
result = arguments[i](result);
} catch (error) {
newError = {name:`${error.name}`,message : `${error.message}`,stack:`${error.stack}`,level:`${error.level}`}
errors.push(newError)
} finally{
continue iterations;
}
}
}
const finalResult = {
errors :errors,
value: result
}
return finalResult;
}
function square(n){
return n*2
}
function million(){
return 1000000
}
function divideTwo(n){
return n/2;
}
console.log(combine(million,square,divideTwo))
I was tasked with creating a combine function that can take an unlimited number of arguments. It functions correctly when all arguments are functions, but if an error occurs, it should handle it and skip the iteration without breaking the program. How can I handle this scenario correctly?