JSFiddle - React, Tailwind, and code Playground

by Harsh Kansagara

JavaScript

function one(){
return 'Hello';
}

function two(){
return true;
}

function three(){
return 'Hi'
}

const chain = [one,two,three];

function chainSolver(chain){
	let res = [];
	for(var i=0; i<=chain.length - 1; i++ ){
  	if(chain[i]()){
    	const res_=chain[i]();
    	res.push(res_);
    }else{
    	break;
    }
  }
  return res;
}

console.log(chainSolver(chain));