1Promise.myAll = function (promises) {
2 var count = promises.length
3 var result = new Array(count).fill(false)
4 return new Promise((resolve, reject) => {
5 var checkIfDone = () => {
6 if (--count === 0) resolve(result)
7 }
8 promises.forEach((promise, index) => {
9 promise.then( (x) => {
10 result[index] = x
11 }, reject).then(checkIfDone)
12 })
13 })
14}
1Promise.allSettled = function (promises) {
2 let mappedPromises = promises.map((p) => {
3 return p
4 .then((value) => {
5 return {
6 status: 'fulfilled',
7 value,
8 };
9 })
10 .catch((reason) => {
11 return {
12 status: 'rejected',
13 reason,
14 };
15 });
16 });
17 return Promise.all(mappedPromises);};