function myPromiseAll(arr) {
let result = []
let count = 1

return new Promise((resolve, reject) => {
for (let i = 0; i < arr.length; i++) {
Promise.resolve(arr[i]).then(res => {
// console.log(i)
result[i] = res
// console.log(res)
if (arr.length == res.length ) {
resolve (result)
}
}, reject)
}
})

}
// let p1 = Promise.resolve(3);
// let p2 = 1337;
// let p3 = new Promise((resolve, reject) => {
// setTimeout(resolve, 100, 'foo');
// });
// myPromiseAll([p1, p2, p3]).then(values => {
// console.log(values); // [3, 1337, "foo"]
// })

let p1 = new Promise((resolve, reject) => {
setTimeout(resolve, 1000, 'one');
});
let p2 = new Promise((resolve, reject) => {
setTimeout(resolve, 2000, 'two');
});
let p3 = new Promise((resolve, reject) => {
setTimeout(resolve, 3000, 'three');
});
let p4 = new Promise((resolve, reject) => {
setTimeout(resolve, 4000, 'four');
});
let p5 = new Promise((resolve, reject) => {
reject('reject');
});

myPromiseAll([p1, p2, p3, p4, p5]).then(values => {
// console.log(values);
}, reason => {
console.log(reason);// reject
});