Promise.all = function(promises) { return new Promise((resolve, reject) => { const result = []; let count = 0; if (promises.length === 0) { resolve(result); } else { for (let i = 0; i < promises.length; i++) { Promise.resolve(promises[i]).then(res => { result[i] = res; count++; if (count === promises.length) { resolve(result); } }, err => { reject(err); }); } } }); }