I have a 3 function:
First just returns the value
Second calls a setTimeout
Third returns promise with the value
I can't touch these 3 functions.
Here they are:
const A = "A";
const B = "B";
const C = "C";
function getA() {
return A;
}
function getB(callback) {
setTimeout(() => {
callback(B);
}, 10);
}
function getC() {
return Promise.resolve().then(() => C);
}
I need to create a function which will return the output of all three function in the array with promise.
So far I tried this:
function getABC() {
return new Promise((resolve, reject) => {
let a = getA();
let b = getB(B => B);
let c = getC().then(() => C);
let arr = [a, b, c];
resolve(arr);
}).then((arr) => arr);
}
getABC().then((arr) => console.log(arr));
It should return ['A', 'B', 'C']
but instead it returns ['A', undefined, Promise {<pending>}]
;
I tried different approaches but they were all false.