Implement a Custom Polyfill for Promise.all()

Build your own version of Promise.all() from scratch. It should accept an iterable of promises, resolve only when every promise resolves (returning an array of results in order), and reject immediately if any single promise rejects. Edge cases to handle include non-promise values in the input, empty arrays, and maintaining result index order regardless of resolution order. Asked heavily at FAANG and top product companies.

Examples
Input: []
Output:
Hints

Implement a Custom Polyfill for Promise.all()

Build your own version of Promise.all() from scratch. It should accept an iterable of promises, resolve only when every promise resolves (returning an array of results in order), and reject immediately if any single promise rejects. Edge cases to handle include non-promise values in the input, empty arrays, and maintaining result index order regardless of resolution order. Asked heavily at FAANG and top product companies.