Promise.all = function (iterator) {
return new Promise((resolve, reject) => {
let count = 0;
let res = [];
for (let i in iterator) {
Promise.resolve(iterator[i])
.then(value => {
res[i] = value;
count++;
if (count === iterator.length) {
return resolve(res);
}
}, error => {
return reject(error)
});
}
})
}