Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save stewones/c806cce30349001926d0cfa6087a3a96 to your computer and use it in GitHub Desktop.
Save stewones/c806cce30349001926d0cfa6087a3a96 to your computer and use it in GitHub Desktop.
problema em utilizar o if com catsh
let _ = require('lodash');
let games = [
{
name: 'Street Fighter',
year: 1990
},
{
name: 'Mortal Kombat' ,
year: 1991
},
{
name: 'Top Gear' ,
year: 1992
}
]
function busca(pesquisa){
return new Promise((resolve, rejeita) =>{
setTimeout( ()=>{
let resposta = _.find(games, (jogo_atual)=>{
return jogo_atual.name == pesquisa
})
if (!resposta){
rejeita('objeto nao encontrado');
}else{
resolve(resposta)}}
,5*1000);
});
}
console.log('Carregando ....')
busca('Top Gar').then( (resposta)=>console.log('o jogo encontrado foi: ',resposta))
.catch((e)=>{
console.log('objeto nao encontrado')
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment