El siguiente código se explica por sí mismo. Tengo una serie de funciones de validación que pueden ser síncronas o asíncronas. Quiero mapear esa matriz, esperar cualquier promesa que se requiera y devolver una matriz que contenga todos los resultados de las funciones del validador. Parece que no puedo hacer esto con el .map() nativo
const syncValidator = () => 'Valid'; const asyncValidator = async () => { await new Promise(resolve => setTimeout(resolve, 1000)); return "Async validation error"; }; const validations = [syncValidator, asyncValidator]; // Function to find the results of all the validations const validateSchema = async (validatorArray, inputValue) => { const results = await validatorArray.map( async validationFunc => { const validation = await validationFunc(inputValue); return validation; } ); return results; } (async () => { const ans = await validateSchema(validations, 'blahblah'); // Expected answer: ['Valid', 'Async validation error'] console.log("Ans: ", ans) // Incorrect answer: [ Promise {}, Promise {} ] })();