Only change the ABC function, how can I get the output in the same order as the function present in the D variable. I have tried using async-await but getting the output as ['123', 'ankit', '345'] because of the timeout event.
const A = (dev) => {
setTimeout(() => {
dev('ankit')
}, 300)
}
const B = (dev) => {
setTimeout(() => {
dev('123')
}, 50)
}
const C = (dev) => {
setTimeout(() => {
dev('345')
}, 500)
}
const D = [A, B, C]
const ABC = (args, dev) => {
// write your code here
Promise.all(D.map(async (fun1) => {
return await fun1(dev)
}))
}
ABC(D, (result) => {
console.log('result:', result) // ['ankit', 123, 345]
})