Created
November 23, 2022 23:13
-
-
Save Klerith/f4dc015b001b6a1c471b16c19fdba6d3 to your computer and use it in GitHub Desktop.
Ejercicio para practicar el for await y for if
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { heroes } from '../data/heroes'; | |
/** | |
* | |
* @param {HTMLDivElement} element | |
*/ | |
export const forAwaitComponent = async( element ) => { | |
} | |
/** | |
* | |
* @param {Array<String>} heroIds | |
* @returns {Array<Promise>} | |
*/ | |
const getHeroesAsync = ( heroIds ) => { | |
const heroPromises = []; | |
heroIds.forEach( id => { | |
heroPromises.push( getHeroAsync(id) ); | |
}); | |
return heroPromises; | |
} | |
const getHeroAsync = async(id) => { | |
await new Promise(( resolve ) => { | |
setTimeout(() => resolve(), 1000) | |
}); | |
return heroes.find( hero => hero.id === id ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment