How to implement Promise.all? | Promise Polyfills | Advanced JavaScript Interview Question
@Yomesh Gupta

As per the MDN,

The Promise.all() method takes an iterable of promises as an input, and returns a single Promise that resolves to an array of the results of the input promises. This returned promise will resolve when all of the input's promises have resolved, or if the input iterable contains no promises. It rejects immediately upon any of the input promises rejecting or non-promises throwing an error, and will reject with this first rejection message / error.

For example --

function init() {
    return Promise.resolve(1);

const promises = [

Promise.all(promises).then(values => {
    // [1, 1, 1]

In this question, you need to implement the Promise.all from scratch.

Loading IDE...