function first(cb) {
setTimeout(() => {
console.log('first');
cb();
}, 1000);
}
function second(cb) {
setTimeout(() => {
console.log('second');
cb();
}, 1000);
}
function third(cb) {
setTimeout(() => {
console.log('third');
cb();
}, 1000);
}
function executeFunctions() {
const innerFunction = (index, functions) => {
if (index >= functions.length) {
console.log('All functions completed');
return;
}
functions[index](() => innerFunction(index + 1, functions));
};
innerFunction(0, [first, second, third]);
}
executeFunctions();