Skip to content

Instantly share code, notes, and snippets.

@Klerith
Created November 23, 2022 23:13
Show Gist options
  • Save Klerith/f4dc015b001b6a1c471b16c19fdba6d3 to your computer and use it in GitHub Desktop.
Save Klerith/f4dc015b001b6a1c471b16c19fdba6d3 to your computer and use it in GitHub Desktop.
Ejercicio para practicar el for await y for if
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