Skip to content

Instantly share code, notes, and snippets.

View conorhastings's full-sized avatar
🏄‍♂️
9-5, just to make a living

Conor Hastings conorhastings

🏄‍♂️
9-5, just to make a living
View GitHub Profile
// The function
function subscribe(promises, cb) {
let result = Array.from({ length: promises.length }).fill(null);
promises.forEach((promise, index) => {
promise.then(val => {
const clonedResult = [...result];
clonedResult[index] = val;
cb(clonedResult);
result = clonedResult;