Implement a custom Promise.all() method

Promise.all is a method in JavaScript that takes an iterable of promises as input and returns a single promise that resolves when all of the input promises have resolved or when any of the input promises rejects.

This returned promise resolves with an array of the results of the input promises in the same order as they were passed in.

Example

const promise1 = Promise.resolve(3);
const promise2 = 42;
const promise3 = new Promise((resolve, reject) => {
  setTimeout(resolve, 100, 'foo');
});

Promise.all([promise1, promise2, promise3]).then((values) => {
  console.log(values); // expected output: Array [3, 42, "foo"]
});